X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 139A85647F for ; Tue, 1 Mar 2005 01:27:36 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21276-02 for ; Tue, 1 Mar 2005 01:27:34 +0000 (GMT) Received: from MM01SNLNTO.son.sandia.gov (mm01snlnto.sandia.gov [132.175.109.20]) by svr1.postgresql.org (Postfix) with ESMTP id 3D9E7564B0 for ; Tue, 1 Mar 2005 01:27:33 +0000 (GMT) Received: from 132.175.109.4 by mm02snlnto.son.sandia.gov with ESMTP ( Tumbleweed MMS SMTP Relay 01 (MMS v5.6.3)); Mon, 28 Feb 2005 18:27:26 -0700 X-Server-Uuid: 914ACFB1-8EBC-470E-882B-54A00EED9786 Received: from ES22SNLNT.srn.sandia.gov (ec03snlnt.sandia.gov [134.253.164.158] (may be forged)) by mailgate2.sandia.gov ( 8.12.11/8.12.11) with ESMTP id j211ROtn005167; Mon, 28 Feb 2005 18:27: 25 -0700 (MST) Received: from 134.252.13.164 ([134.252.13.164]) by ES22SNLNT.srn.sandia.gov ([134.253.164.160]) with Microsoft Exchange Server HTTP-DAV ; Tue, 1 Mar 2005 01:27:24 +0000 Received: from boomerang by ES22SNLNT.srn.sandia.gov; 01 Mar 2005 01:25: 56 +0000 Subject: Re: table constraints From: "Casey T. Deccio" To: andrew@supernews.com Cc: pgsql-sql@postgresql.org In-Reply-To: References: <1109618910.32166.0.camel@boomerang.ran.sandia.gov> <20050228202016.GA32034@wolff.to> <1109622215.32226.11.camel@boomerang.ran.sandia.gov> Organization: Sandia National Laboratories Date: Mon, 28 Feb 2005 17:25:56 -0800 Message-ID: <1109640356.32228.53.camel@boomerang.ran.sandia.gov> MIME-Version: 1.0 X-Mailer: Evolution 2.0.3 X-PMX-Version: 4.7.0.111621, Antispam-Engine: 2.0.1.0, Antispam-Data: 2005.2.28.15 X-WSS-ID: 6E3D1B741JG939741-01-01 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.32 tagged_above=0 required=5 tests=AWL, RCVD_NUMERIC_HELO X-Spam-Level: * X-Archive-Number: 200503/4 X-Sequence-Number: 20483 On Mon, 2005-02-28 at 18:01 -0700, Andrew - Supernews wrote: > The CHECK is obviously being evaluated prior to the actual insertion > of > the record, whereas the logic of your function clearly expects to be > evaluated after the insertion. > I finally came to that conclusion just a few minutes before I got this email. However, it was your email that made it quite clear why this was. > Allowing non-immutable functions in CHECK is probably an error, since > it > can lead to tables which can not be dumped+restored (consider in your > example what happens when the constraint becomes false as a result of > deleting a row - at that point, a dump and restore of the table will > fail, > since the constraint can not be defined after loading the data if it > is > violated by that data). > Using triggers is a more reliable way to do this sort of thing - at > least > then it is clear that you are checking the data only at the time of > modification, whereas CHECK constraints are declarative constraints > which > are expected to be true at all times. > This is a very good point. I've now implemented the check with a trigger, and it works very well. Thanks for the input and the logic. Casey