Re: Tables Referencing themselves As Foreign Keys

From: Arjen van der Meijden <acmmailing(at)vulcanus(dot)its(dot)tudelft(dot)nl>
To: "Tony (Unihost)" <tony(at)unihost(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Tables Referencing themselves As Foreign Keys
Date: 2003-12-22 11:36:47
Message-ID: 3FE6D74F.2070903@vulcanus.its.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tony,

That'll work, but you have to mind the first row/toprow you insert.
Will it have no parent (make the field nullable) or will it be its own
parent (you'll have to test whether that works, I don't know, foreign
keys are deferrable, so it should be possible if you specify that).

Best regards,

Arjen

Tony (Unihost) wrote:

> Hi,
>
> I'm still new to this so if I'm sounding dumb or my premise is flawed
> please forgive me. I have a DB design which contains a table which has
> categories, each category has a parent category, and is recursed until
> the top category is reached, in order to create breadcrumbs. Is there
> any problem with using foreign keys to reference the same table? So a
> when category is added the CatParent MUST be present as a CatID
>
> CatID - Serial
> CatParent - int4 - References CatID
> CatName - Text
>
> Am I likeley to come unstuck with this?
>
> Cheers
>
> T.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2003-12-22 12:00:50 Re: Tables Referencing themselves As Foreign Keys
Previous Message Pavel Stehule 2003-12-22 11:34:51 Re: extracting date FROM timestamp