Re: Subselects in CHECK clause ...

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: James Robinson <jlrobins(at)socialserve(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Subselects in CHECK clause ...
Date: 2006-11-29 17:53:16
Message-ID: 20061129094826.X4910@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Wed, 29 Nov 2006, James Robinson wrote:

> I see that subselects are not directly supported in check clauses,
> but one can work around that by writing a stored function which
> returns boolean and performs the subselect. Are there any known
> gotchas with doing this?

To completely get the constraint, you have to also apply constraints on
the tables referenced in the function that prevent modifications on those
tables from causing the constraint to be violated. For example, if you
were to do an exists test on another table for a row that matches up with
this row in some fashion (for a specialized referential integrity
constraint) modifications on that other table could also cause the
constraint to be violated, but that isn't caught by the CHECK
function(...) case and you'll probably need triggers or other constraints
on that table.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message James Robinson 2006-11-29 17:59:50 Re: Subselects in CHECK clause ...
Previous Message Jeff Herrin 2006-11-29 17:32:56 Re: consistent random order