TG_OP and undefined OLD values

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: TG_OP and undefined OLD values
Date: 2005-08-26 15:49:08
Message-ID: 200508261549.j7QFn9Rf016956@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm trying to write some code in a trigger that fires on both an insert
and an update.

At one point I need to update a column either on an insert or if the
value of the column has changed.

The following code fails because the OLD value is not defined:

if TG_OP = ''INSERT''
or (TG_OP = ''UPDATE'' and NEW.column1 != coalesce(OLD.column1,''--'')) then
column2 := ''CHANGED'';
end if;

Shouldn't OLD.column1 not even be evaluated when the other if statement in
the group in parentheses is false or when the earlier if statement is true?

Is there a way around this other than separating the code into two
independent if statements, duplicating the action statements?
--
Mike Nolan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Wilson 2005-08-26 15:52:27 Re: bytea or large objects?
Previous Message Chris Browne 2005-08-26 15:35:36 Re: Postgresql replication