Using OLD on INSERT

From: Paul Makepeace <postgresql(dot)org(at)paulm(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Using OLD on INSERT
Date: 2004-01-22 13:29:44
Message-ID: 20040122132944.GN26240@mythix.realprogrammers.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Terry Lee Tucker 2004-01-22 14:26:09 Re: Using OLD on INSERT
Previous Message Tom Lane 2004-01-21 21:12:53 Re: passwords