pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: James Robinson <jlrobins@socialserve.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Subselects in CHECK clause ...
Date: Wed, 29 Nov 2006 09:53:16 -0800 (PST)
Message-ID: <20061129094826.X4910@megazone.bigpanda.com> (raw)
In-Reply-To: <6881FC4D-8F7C-477B-9AAA-C9B5282D88B2@socialserve.com>
References: <6881FC4D-8F7C-477B-9AAA-C9B5282D88B2@socialserve.com>


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.




view thread (3+ messages)  latest in thread

Message-ID: <20061129094826.X4910@megazone.bigpanda.com>
Permalink:  ../20061129094826.X4910@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20061129094826.X4910@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, jlrobins@socialserve.com
  Subject: Re: Subselects in CHECK clause ...
  In-Reply-To: <20061129094826.X4910@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox