Re: Using OLD on INSERT - Mailing list pgsql-novice

From Terry Lee Tucker
Subject Re: Using OLD on INSERT
Date
Msg-id 200401220839.07572.terry@esc1.com
Whole thread Raw
In response to Using OLD on INSERT  (Paul Makepeace <postgresql.org@paulm.com>)
Responses Re: Using OLD on INSERT  (Terry Lee Tucker <terry@esc1.com>)
List pgsql-novice
We check the value of TG_OP as in:
IF TG_OP = ''UPDATE'' THEN
    Code that address OLD and NEW here;
ELSE
    Code that addresses only NEW here.
END IF;

On Thursday 22 January 2004 08:29 am, Paul Makepeace wrote:
> I have a trigger that sets an expires column to
> last_access+expiry::interval if expires IS NULL or if the expires value
> isn't being set or changed.
>
>   IF NEW.expires IS NULL OR NEW.expires = OLD.expires THEN
>       NEW.expires = NEW.last_access+NEW.expiry:interval;
>   END IF;
>
> The problem here is OLD doesn't exist on the first INSERT which throws
> an error. It seems PL/pgSQL doesn't have C's short-circuit booleans.
>
> a) Is there a way around this?
> b) is there a 'right' way to determine if a column is being changed?
>
> Paul (total PL/pgSQL newbie)

--
Quote: 8
"Even now politicians use the phrase 'federal dollars' as a synonym for
 'free money.' It's a dangerous tendency, for it leaves the states
 accountable to Washington rather than to their own voters. This mix of
 state and federal governments is not just economically suspect but
 politically corrosive; it undermines the essence of real federalism:
 the integrity of both state and federal governments. If we're serious
 about states' rights, then we need to get serious about states'
 responsibilities. The two go together. As with love and marriage, you
 can't have one without the other."

 --Paul Greenberg

 Work: 1-336-372-6812
 Cell: 1-336-363-4719
email: terry@esc1.com

pgsql-novice by date:

Previous
From: Iandé Coutinho
Date:
Subject: executing backup remotly
Next
From: Terry Lee Tucker
Date:
Subject: Re: Using OLD on INSERT