Skip site navigation (1) Skip section navigation (2)

Re: Trigger function to know which fields are being updated

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: Bernard Cheung <cheungsw(at)hotmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Trigger function to know which fields are being updated
Date: 2004-05-10 21:38:56
Message-ID: 20040510213856.65983.qmail@web20812.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-sql
--- Bernard Cheung <cheungsw(at)hotmail(dot)com> 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(at)postgresql(dot)org



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

In response to

pgsql-sql by date

Next:From: Stephan SzaboDate: 2004-05-10 22:09:43
Subject: Re: update table where rows are selected by inner join?
Previous:From: Bruce MomjianDate: 2004-05-10 21:26:05
Subject: Re: Adding MERGE to the TODO list (resend with subject)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group