Problems with NEW.* in triggers

From: Jamie Lawrence <postgres(at)jal(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Problems with NEW.* in triggers
Date: 2003-11-04 22:33:19
Message-ID: 20031104223319.GA2879@clueinc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
return NEW;
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(at)jal(dot)org
Never eat anything bigger than your head.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-11-04 22:48:34 Re: Problems with NEW.* in triggers
Previous Message Franco Bruno Borghesi 2003-11-04 21:28:12 What's wrong with this group by clause?