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

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Mike Christensen <mike(at)kitchenpc(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Constraint to ensure value does NOT exist in another table?
Date: 2011-06-16 06:36:40
Message-ID: BANLkTinZK4YoLJBfWbzipY7cgynyiVdKdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 16, 2011 at 6:04 AM, Mike Christensen <mike(at)kitchenpc(dot)com> wrote:

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

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2011-06-16 06:47:32 Re: Symbols and versioning of binary releases; running a symbol server
Previous Message Mike Christensen 2011-06-16 05:39:19 Re: You could be a PostgreSQL Patch Reviewer!