Re: Self referencing composite datatype

Поиск
Список
Период
Сортировка
От Sergey Konoplev
Тема Re: Self referencing composite datatype
Дата
Msg-id CAL_0b1ujSes0=2bFvTnpu3nFkTNhmkn5QQo8tPuhPWYhEqEwzg@mail.gmail.com
обсуждение исходный текст
Ответ на Self referencing composite datatype  (Sameer Thakur <samthakur74@gmail.com>)
Ответы Re: Self referencing composite datatype
Re: Self referencing composite datatype
Список pgsql-general
On Wed, Aug 7, 2013 at 4:57 AM, Sameer Thakur <samthakur74@gmail.com> wrote:
> I wanted to create a composite datatype to represent a Node. So it would
> have a few attributes and an array of type Node which is the children of
> this node.
> create type Node as (r integer, s integer, children Node []);
> But i get error type Node[] does not exist. I understand that Node is not
> defined hence the error.
> But how do i get around this problem?

I just wonder how are you going to use this kind of types?

In 9.3 you will be able to use foreign keys with arrays like it is describe here
http://blog.2ndquadrant.com/postgresql-9-3-development-array-element-foreign-keys/

eg.

create table node as (
  id integer primary key,
  r integer, s integer,
  children integer[] element references node
);

so you could download 9.3rc2 and experimant with it.

Now (on <=9.2.x) you can create the table without FK

create table node as (
  id integer primary key,
  r integer, s integer,
  children integer[]
);

and check integrity by triggers.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray.ru@gmail.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Victor Hooi
Дата:
Сообщение: Performance of ORDER BY RANDOM to select random rows?
Следующее
От: Sergey Konoplev
Дата:
Сообщение: Re: Self referencing composite datatype