Problems with NEW.* in triggers - Mailing list pgsql-sql

From Jamie Lawrence
Subject Problems with NEW.* in triggers
Date
Msg-id 20031104223319.GA2879@clueinc.net
Whole thread Raw
Responses Re: Problems with NEW.* in triggers  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Problems with NEW.* in triggers  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
Hi folks -

I'm having a problem with what looks like it should be trivial.

For the function

create or replace function timestamp_fn() returns opaque as '       begin       NEW.moddate := coalesce(NEW.moddate,
now());      return NEW;       end
 
' language 'plpgsql';

on an after insert or update trigger, never sets moddate to now().

I had thought that if moddate isn't included in an insert or update,
that it would be null in the NEW context, so that this would fall 
through to the now() call. (I also tried this as below:

create or replace function timestamp_fn() returns opaque as '    begin    if NEW.moddate is not null then
returnNEW;    else            NEW.moddate := now();            return NEW;    end if;     end
 
' language 'plpgsql';

With the same results.)

Any thoughts on what I'm doing wrong??

-j


-- 
Jamie Lawrence                                        jal@jal.org
Never eat anything bigger than your head.




pgsql-sql by date:

Previous
From: "Senthil Kumar S"
Date:
Subject: Re: Error message during compressed backup
Next
From: Tom Lane
Date:
Subject: Re: Problems with NEW.* in triggers