From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Rudi Starcevic <rudi@oasis.net.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sub Select inside Check ?
Date: Tue, 25 Feb 2003 07:50:13 -0800 (PST)
Message-ID: <20030225074841.X57635-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <3E5B03B9.4070500@oasis.net.au>
On Tue, 25 Feb 2003, Rudi Starcevic wrote:
> I'm trying to create this table with a Check that fails.
>
> I'm using 'Check' instead of 'References' due to poor db schema ( before
> me .. )
>
> Here is my error message:
> ERROR: cannot use subselect in CHECK constraint expression
>
> CREATE TABLE cp_retailers
> (
> ret_id serial PRIMARY KEY,
> ret_name varchar(120) NOT NULL,
> ret_address1 varchar(120),
> ret_address2 varchar(120),
> sub_id integer NOT NULL CHECK
> ( EXISTS
> ( SELECT sub_id FROM suburbs )
> )
> );
>
> I guess that say's it all - no sub select's in Check or am I on the
> wrong track ?
Unfortunately, that's not supported (it's non-trivial). If you're
looking only for an insert/update on cp_retailers check (ie, suburbs
is unlikely to be updated/deleted from), you can do this by hiding
the subselect in a function and using that in the check. If you
need both direction checks it gets rather complicated to do well, but
you can come fairly close using after triggers.
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@megazone23.bigpanda.com, rudi@oasis.net.au
Subject: Re: Sub Select inside Check ?
In-Reply-To: <20030225074841.X57635-100000@megazone23.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