Using OLD on INSERT - Mailing list pgsql-novice

From Paul Makepeace
Subject Using OLD on INSERT
Date
Msg-id 20040122132944.GN26240@mythix.realprogrammers.com
Whole thread Raw
Responses Re: Using OLD on INSERT
Re: Using OLD on INSERT
List pgsql-novice
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)

--
Paul Makepeace ................................  http://paulm.com/ecademy

"If I had new shoes, then he wouldn't sing Halleighluha."
   -- http://paulm.com/toys/surrealism/

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: passwords
Next
From: Iandé Coutinho
Date:
Subject: executing backup remotly