Re: Foreign Key with Constant - Mailing list pgsql-general

From Gregory Wood
Subject Re: Foreign Key with Constant
Date
Msg-id 074101c2d9dd$dd7e58c0$4f89ffcc@eng3
Whole thread Raw
In response to Re: Foreign Key with Constant  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-general
> > Is it possible to create a foreign key that uses a constant for one of
the
> > fields. In other words, I want to foreign key one value into another
table,
>
> Not directly no.

*nod* I figured as much.

> > I'd rather do this without adding a 'constant' column, or messing too
> > extensively without triggers, but I fear that one of these might be
> > necessary.
>
> Unfortunately I think you'll need to do either the constant column or
> triggers (the SQL mandated way of solving this is probably check
> constraints with subselects but we don't support that)  If you only
> care about insert time on the fk table and not about moidfications to the
> pk table you can get away with a simple function that you use in a check
> constraint I think.

Actually, I think that sounds like the best solution. It will be a
relatively infrequently used table and I'd like to keep things simple (not
cluttering up the design with extra columns and triggers).

Thanks!

Greg


pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Mutating table (urgent)
Next
From: Oleg Samoylov
Date:
Subject: Re: system catalog