X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7ECC9D1D9C2 for ; Mon, 22 Mar 2004 11:23:01 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 50022-05 for ; Mon, 22 Mar 2004 07:23:07 -0400 (AST) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 405CAD1DCB2 for ; Mon, 22 Mar 2004 07:22:59 -0400 (AST) Received: (qmail 32144 invoked by uid 500); 22 Mar 2004 11:26:04 -0000 Date: Mon, 22 Mar 2004 05:26:04 -0600 From: Bruno Wolff III To: Erik Thiele Cc: pgsql-sql@postgresql.org Subject: Re: special integrity constraints Message-ID: <20040322112604.GA31222@wolff.to> Mail-Followup-To: Erik Thiele , pgsql-sql@postgresql.org References: <20040322102031.6a6f0b77.erik@thiele-hydraulik.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040322102031.6a6f0b77.erik@thiele-hydraulik.de> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/212 X-Sequence-Number: 17311 On Mon, Mar 22, 2004 at 10:20:31 +0100, Erik Thiele wrote: > hi, > > i have two tables > > create table a (x integer); > create table b (y real); > > i have the special constraint that the sum of the number of rows in > table a plus the number of rows in table b must be even. Does the above mean that the number of rows in a is equal to the number of rows in b or that their sum is divisible by 2? > so there is a posibility of adding one element to a and one element to > b, and again the constraint is met. > > but this of course does not work, since between adding the element to a > and adding the element to b, the constraint is not met. > > so i cannot use a trigger. > > what i need is the execution of a check procedure at commit time. is > that somehow possible? Do the real tables have candidate keys? If so you can use foreign key references to pair a row in a to a row b (though I am not sure this is what your real constraint is).