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 634B8D1DACB for ; Mon, 22 Mar 2004 11:38:37 +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 57473-03 for ; Mon, 22 Mar 2004 07:38:43 -0400 (AST) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id 865EDD1D58C for ; Mon, 22 Mar 2004 07:38:34 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id i2MBeBNu031837; Mon, 22 Mar 2004 13:40:11 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id i2MBeBwP031833; Mon, 22 Mar 2004 13:40:11 +0200 Date: Mon, 22 Mar 2004 13:40:11 +0200 (EET) From: Achilleus Mantzios To: Erik Thiele Cc: pgsql-sql@postgresql.org Subject: Re: special integrity constraints In-Reply-To: <20040322112659.4553df76.erik@thiele-hydraulik.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/214 X-Sequence-Number: 17313 O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > On Mon, 22 Mar 2004 12:13:29 +0200 (EET) > Achilleus Mantzios wrote: > > > O kyrios Erik Thiele egrapse stis Mar 22, 2004 : > > > > Did you check out the DEFERRABLE option on the constraint? > > > > DEFERRABLE > NOT DEFERRABLE > > This controls whether the constraint can be deferred. A constraint that > is not deferrable will be checked immediately after every command. > Checking of constraints that are deferrable may be postponed until the > end of the transaction (using the SET CONSTRAINTS command). NOT > DEFERRABLE is the default. > > !!!! Only foreign key constraints currently accept > this clause. All other constraint types are not deferrable. !!!! > Ooops . Then i guess you have to convert your problem to use FK constraints. Add 2 additional 1 row tables "abnum" and "even" and write 2 triggers (on a,b) that keep up to date the value of the single row of abnum. (thatis num(a)+num(b) % 2). Then INSERT INTO even(num) VALUES(0); Then make 1<-->1 relationship between abnum,even using DEFERRABLE FK constraints. At the end of each xaction the num(a)+num(b) % 2 must equal to 0 (i.e. an even number). Whats your results? > my constraint is not a foreign key constraint.... > > cya! > erik > > > > 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. > > > > > > 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? > > > > > > my database has much more tables than just a and b, and most time > > > the other tables are modified and not a or b, so it would be nice to > > > execute the constraint checking procedure only if a or b was > > > modified. > > > > > > yes :) this question i asked in my former mail too, but I think it > > > looked like there was a workaround and my problem was wrong. so i > > > created this new kind of problem here to make things clearer. > > > > > > > > > cu > > > Erik > > > > > > > > > > > > > -- > > -Achilleus > > > > > -- -Achilleus