This seems to be a bug: Create Table tab1 (f1 integer); Create Function tot_of_tab1() returns integer as 'select cast(sum(f1) as int4) from tab1' language 'sql'; Alter Table tab1 add check(tot_of_tab1() > 0); zzz=# insert into tab1 values(1); INSERT 142380 1 zzz=# insert into tab1 values(-10); INSERT 142381 1 zzz=# select tot_of_tab1(); tot_of_tab1 ------------- -9 (1 row) zzz=# insert into tab1 values(-12); ERROR: ExecAppend: rejected due to CHECK constraint $1 The constraint should have failed on the second insert. Maybe the constraint is evaluate before the insert? ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/