From: | Leif Biberg Kristensen <leif(at)solumslekt(dot)org> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Self-referential records |
Date: | 2010-01-24 14:03:39 |
Message-ID: | 201001241503.39285.leif@solumslekt.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sunday 24. January 2010 14.43.10 Ovid wrote:
> Assuming I have the following table:
>
> CREATE TABLE refers (
> id SERIAL PRIMARY KEY,
> name VARCHAR(255) NOT NULL,
> parent_id INTEGER NOT NULL,
> FOREIGN KEY (parent_id) REFERENCES refers(id)
> );
> I need to insert two records so that "select * from refers" looks like this:
>
> =# select * from refers;
> id | name | parent_id
> ----+------+-----------
> 1 | xxxx | 1
> 2 | yyy | 2
>
> The first record can't be inserted because I don't yet know the parent_id.
I've got a similar structure. I just declared the root node with both id and
parent_id=0.
regards,
--
Leif Biberg Kristensen
http://solumslekt.org/
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Moran | 2010-01-24 14:18:19 | Re: Self-referential records |
Previous Message | Ovid | 2010-01-24 13:43:10 | Self-referential records |