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

Re: Triggers - need help !!!

From: SZUCS Gábor <surrano(at)mailbox(dot)hu>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Triggers - need help !!!
Date: 2004-07-08 11:19:28
Message-ID: 005801c464dd$72b5bec0$0403a8c0@fejleszt4 (view raw or flat)
Thread:
Lists: pgsql-sql
I'd like to add that a NULL value might mess things up. If CreateTime may be
null, try this:

  if (OLD.CreateTime <> NEW.CreateTime) OR
     (OLD.CreateTime ISNULL <> NEW.CreateTime ISNULL) THEN ...

or this:

  if COALESCE(OLD.CreateTime, '3001-01-01') <>
     COALESCE(NEW.CreateTime, '3001-01-01') THEN ...

(provided you can safely assume that createtimes remain in this millenium
;) )

or maybe:

  if COALESCE(OLD.CreateTime <> NEW.CreateTime,
              OLD.CreateTime ISNULL <> NEW.CreateTime ISNULL) THEN ...

However; I'd stay with the first one. It's quite simple and Y3K-safe ;)
Also, it seems to be the most effective of them, if any.

G.
%----------------------- cut here -----------------------%
\end

----- Original Message ----- 
From: "Richard Huxton" <dev(at)archonet(dot)com>
Sent: Wednesday, July 07, 2004 1:03 PM


> Pradeepkumar, Pyatalo (IE10) wrote:
> > Thanks a lot for ur help.
> >  In the trigger, I am checking if a field is updated or not. The syntax
I
> > use is
> >
> > IF UPDATE(CreateTime) THEN
> > ....
> > ....
> > END IF;
> >
> > Is this syntax correct.
>
> No, and I don't recall seeing anything like it in the manuals.
>
> IF OLD.CreateTime <> NEW.CreateTime THEN
>   ...


In response to

Responses

pgsql-sql by date

Next:From: Gerwin PhilippoDate: 2004-07-08 12:53:29
Subject: Re: append columns that are null
Previous:From: SZŰCS GáborDate: 2004-07-08 11:09:54
Subject: Constraint->function dependency and dump in 7.3

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