Re: Self referencing composite datatype

From: Chris Travers <chris(dot)travers(at)gmail(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>, Sameer Thakur <samthakur74(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Self referencing composite datatype
Date: 2013-08-08 06:45:57
Message-ID: CAKt_ZfuLK9SVZ58gK9Wr9pm5-aZAyv7dxRiV3zwbkeKWj163Sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Aug 7, 2013 at 11:38 PM, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:

> On Aug 8, 2013, at 4:11, Sergey Konoplev <gray(dot)ru(at)gmail(dot)com> wrote:
>
> > 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.
>
>
> Or, instead of attempting to reference all child nodes from the parent,
> reference the parent node from each child node.
> That's been supported in PG versions like forever and can be queried
> fairly efficiently using recursive CTE's since PG 9.
>

If you do this, have a position number, and use that for ordering. You
need some sort of ordinality here.

Best Wishes,
Chris Travers

>
> Alban Hertroys
> --
> If you can't see the forest for the trees,
> cut the trees and you'll find there is no forest.
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
Best Wishes,
Chris Travers

Efficito: Hosted Accounting and ERP. Robust and Flexible. No vendor
lock-in.
http://www.efficito.com/learn_more.shtml

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jayadevan M 2013-08-08 06:52:03 Re: Replication Postgre > Oracle
Previous Message Sergey Konoplev 2013-08-08 06:43:04 Re: Self referencing composite datatype