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. ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq