Re: Literals in foreign key definitions

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Literals in foreign key definitions
Date: 2010-02-04 19:34:35
Message-ID: m3zl3on6b8.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl> wrote:

> [...]
> Now the intent here is to restrict foreign keys referencing the base class to unitclass records that describe a baseclass and to restrict foreign keys referencing a derived class to unitclass records that do NOT describe a baseclass.
> Basically I'm trying to disallow derived classes to be derived of other derived classes.

> I can of course add a few triggers to force that constraint, but I think it would be nice if the above syntax could be made to work. Or is this already in 8.4 or 8.5 or is this a can of worms? Does the SQL spec disallow it?

If you want to avoid triggers, another, simpler approach is
to have a otherwise superfluous column "is_baseclass" with a
default "TRUE" and constraints "NOT NULL" and
"CHECK(is_baseclass)" and then use a "normal" foreign key
constraint. I usually find that easier to read as it's more
familiar.

Tim

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Owen Hartnett 2010-02-04 20:44:06 Re: Re: PG fails on Windows Server 2008: could not reattach to shared memory ... : 487
Previous Message Adrian Klaver 2010-02-04 19:19:40 Re: Any Good Postgresql Courses Offered in the US Area?