Re: subselect in CHECK constraint? - Mailing list pgsql-general

From Tom Lane
Subject Re: subselect in CHECK constraint?
Date
Msg-id 14579.968087411@sss.pgh.pa.us
Whole thread Raw
In response to Re: subselect in CHECK constraint?  (Ian Turner <vectro@pipeline.com>)
Responses Re: subselect in CHECK constraint?
List pgsql-general
Ian Turner <vectro@pipeline.com> writes:
> Uhhh. I get no errors, but it dosen't work, either. Consider:

I didn't say that you would like the semantics ;-).

The check constraint is going to be evaluated *before* the proposed
new tuple is inserted into the table, not after; so doing a select
on the same table won't see the new tuple.

Also, as several other people already pointed out, a constraint
involving a select could be violated in many ways including alteration
or removal of tuples in other tables.  We only evaluate check
constraints when we insert/update tuples in the table they are attached
to...

            regards, tom lane

pgsql-general by date:

Previous
From: Ian Turner
Date:
Subject: Re: subselect in CHECK constraint?
Next
From: "Rafa Couto"
Date:
Subject: RE: Postgres 7.0.2 and ODBC