Re: Constraint to ensure value does NOT exist in another table?

From: Mike Christensen <mike(at)kitchenpc(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Constraint to ensure value does NOT exist in another table?
Date: 2011-06-16 06:50:11
Message-ID: BANLkTi=Ys4mRchmLk7nGf3=-0ww+h5J2_A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>> I know I can setup a FK constraint to make sure Table1.ColA exists in
>> Table2.Key, however what if I want to do the reverse?
>>
>> I want to ensure Table1.ColA does NOT exist in Table2.Key..  Can I do
>> this with any sort of CHECK constraint, trigger, custom function, etc?
>
>
> The most common constraints are provided for, but then after that you
> have to use triggers.
>
> PostgreSQL deliberately doesn't support queries in CHECK constraints
> for this reason.

Thanks! I wrote a Trigger for this and it seems to work fairly well..
I kinda figured that was the obvious way, but thought there might be
some new 9.x feature that made this sort of thing possible.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2011-06-16 07:47:38 PostgreSQL 9.0 or 9.1 ?
Previous Message Magnus Hagander 2011-06-16 06:47:32 Re: Symbols and versioning of binary releases; running a symbol server