X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B3320DBA4E for ; Wed, 23 Nov 2005 13:55:34 -0400 (AST) 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 49109-06 for ; Wed, 23 Nov 2005 17:55:33 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 103F6DBA5A for ; Wed, 23 Nov 2005 13:55:30 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jANHtNHT057884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 23 Nov 2005 10:55:25 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jANHtMrX003876; Wed, 23 Nov 2005 10:55:22 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jANHtME5003875; Wed, 23 Nov 2005 10:55:22 -0700 (MST) (envelope-from mfuhr) Date: Wed, 23 Nov 2005 10:55:22 -0700 From: Michael Fuhr To: hubert depesz lubaczewski Cc: fmiddleton@verizon.net, pgsql-admin@postgresql.org Subject: Re: freezing a particular field in a table Message-ID: <20051123175522.GA3828@winnie.fuhr.org> References: <4383A9B7.7060008@verizon.net> <9e4684ce0511230128y77557be3k2507d6eb1575c1e4@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e4684ce0511230128y77557be3k2507d6eb1575c1e4@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[AWL=0.000, UPPERCASE_25_50=0] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/305 X-Sequence-Number: 19678 On Wed, Nov 23, 2005 at 10:28:01AM +0100, hubert depesz lubaczewski wrote: > IF > (NEW.some_field IS NULL AND OLD.some_field IS NOT NULL) > OR > (NEW.some_field IS NOT NULL AND OLD.some_field IS NULL) > OR > (NEW.some_field IS NOT NULL AND OLD.some_field IS NOT NULL > AND NEW.some_field <> OLD.some_field) > THEN A more succinct expression would be: IF NEW.some_field IS DISTINCT FROM OLD.some_field THEN IS DISTINCT FROM is like <> except that it treats NULL as an ordinary value. > CREATE TRIGGER impossible_to_change BEFORE UPDATE ON some_table FOR EACH ROW > EXECUTE PROCEDURE impossible_to_change(); If the table has other triggers and you don't want them to modify the value either, then the check should probably go in an AFTER trigger. -- Michael Fuhr