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 A2827D1B1D9 for ; Mon, 10 May 2004 18:39:23 -0300 (ADT) 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 14787-05 for ; Mon, 10 May 2004 18:39:05 -0300 (ADT) Received: from web20812.mail.yahoo.com (web20812.mail.yahoo.com [216.136.226.217]) by svr1.postgresql.org (Postfix) with SMTP id A7776D1B224 for ; Mon, 10 May 2004 18:38:54 -0300 (ADT) Message-ID: <20040510213856.65983.qmail@web20812.mail.yahoo.com> Received: from [24.248.12.72] by web20812.mail.yahoo.com via HTTP; Mon, 10 May 2004 14:38:56 PDT Date: Mon, 10 May 2004 14:38:56 -0700 (PDT) From: Jeff Eckermann Subject: Re: Trigger function to know which fields are being updated To: Bernard Cheung , pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.7 tagged_above=0.0 required=5.0 tests=FOR_FREE X-Spam-Level: X-Archive-Number: 200405/90 X-Sequence-Number: 17804 --- Bernard Cheung wrote: > I am writing a trigger function. How can I know > which fields are being > updated in the PL/SQL function? > > For example I have a table here: > > > CREATE TABLE COMPANY ( > COMPANY_ID VARCHAR(10) NOT NULL, > NAME VARCHAR(30), > ADDRESS VARCHAR(30)); > > I want to write a trigger to block all update > statements without updating > NAME. I tried the following code block and it > doesn't work: > > > IF TG_OP = ''UPDATE'' THEN > IF NEW.NAME IS NULL THEN > RAISE NOTICE ''Field NAME must be > provided!''; > END IF; > END IF; That should work. Perhaps "name" is not actually null, but rather an empty string? In that case, your test needs to be: "IF NEW.NAME IS NULL OR NEW.NAME = '''' THEN..." > > Are there any functions like the Oracle's UPDATING() > predicate? > > Bernard Cheung > > _________________________________________________________________ > Linguaphone : Learning English? Get Japanese > lessons for FREE > http://go.msnserver.com/HK/46165.asp > > > ---------------------------(end of > broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover