Re: Self referencing composite datatype - Mailing list pgsql-general

From Sergey Konoplev
Subject Re: Self referencing composite datatype
Date
Msg-id CAL_0b1ujSes0=2bFvTnpu3nFkTNhmkn5QQo8tPuhPWYhEqEwzg@mail.gmail.com
Whole thread Raw
In response to Self referencing composite datatype  (Sameer Thakur <samthakur74@gmail.com>)
Responses Re: Self referencing composite datatype  (Sergey Konoplev <gray.ru@gmail.com>)
Re: Self referencing composite datatype  (Alban Hertroys <haramrae@gmail.com>)
List 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 by date:

Previous
From: Victor Hooi
Date:
Subject: Performance of ORDER BY RANDOM to select random rows?
Next
From: Sergey Konoplev
Date:
Subject: Re: Self referencing composite datatype