Re: subselect in CHECK constraint?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ian Turner <vectro(at)pipeline(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: subselect in CHECK constraint?
Date: 2000-09-04 15:59:56
Message-ID: 14071.968083196@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ian Turner <vectro(at)pipeline(dot)com> writes:
> I'm guessing this means I can't do subselects in CHECK statements.

Right. Pushing the SELECT into a SQL or PLPGSQL function that's called
by the constraint is a good workaround, ie

CHECK (testconstraint(a, b))

where FUNCTION testconstraint(a int, b int) RETURNS bool does all the
heavy lifting. If you use plpgsql there should be a performance
advantage too --- the query plan for the function will be cached for
re-use across calls, which is not true for the text of CHECK conditions.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-09-04 16:34:25 Re: Instability in copying large quantities of data
Previous Message Enrico Comini 2000-09-04 15:57:22 JDBC