Re: Foreign Key with Constant

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Gregory Wood <gregw(at)com-stock(dot)com>
Cc: PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Foreign Key with Constant
Date: 2003-02-21 16:50:17
Message-ID: 20030221084651.L58838-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 21 Feb 2003, Gregory Wood wrote:

> 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.

> 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message elein 2003-02-21 17:45:05 Non-English lists and User Groups
Previous Message Gregory Wood 2003-02-21 16:37:17 Foreign Key with Constant