Search Postgresql Archives

Re: Self referencing composite datatype

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 7, 2013 at 4:57 AM, Sameer Thakur <samthakur74@xxxxxxxxx> 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@xxxxxxxxx


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux