[SQL] CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Mario Splivalo
The 'data integrity' rule for database I'm designing says that any subject we're tracking (persons, companies, whatever) is assigned an agreement that can be in several states: 'Approved', 'Unapproved' or 'Obsolete'. One subject can have only one (or none) 'Approved' or 'Unapproved' agreement, and

[SQL] Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Jasen Betts
On 2010-04-19, Mario Splivalo wrote: > The 'data integrity' rule for database I'm designing says that any > subject we're tracking (persons, companies, whatever) is assigned an > agreement that can be in several states: 'Approved', 'Unapproved' or > 'Obsolete'. One subject can have only one (or no

Re: [SQL] Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Mario Splivalo
Jasen Betts wrote: > ... > >> The 'proper' way to do this (as suggested by earlier posts on this >> mailing list) is to use partial UNIQUE indexes, but I have problem with >> that too: indexes are not part of DDL (no matter that primary key >> constraints and/or unique constraints use indexes to e

Re: [SQL] Re: CHECK constraints with plpgsql functions - check 'fires' BEFORE data modification?

2010-04-19 Thread Tom Lane
Jasen Betts writes: > On 2010-04-19, Mario Splivalo wrote: >> The 'proper' way to do this (as suggested by earlier posts on this >> mailing list) is to use partial UNIQUE indexes, but I have problem with >> that too: indexes are not part of DDL (no matter that primary key >> constraints and/or un