Odd plpgsql behaviour

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Odd plpgsql behaviour
Date: 2004-11-15 07:12:24
Message-ID: 419856D8.3000205@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7.4:

This is what we wanted to do:

IF TG_OP = 'INSERT' OR (TG_OP = 'UPDATE' AND NEW.name != OLD.name) THEN
EXECUTE x;
END IF;

However, we had to write it like this:

IF TG_OP = 'INSERT' THEN
EXECUTE x;
ELSIF TG_OP = 'UPDATE' AND NEW.name != OLD.name THEN
EXECUTE x;
END IF;

Because in the first case it would complain that OLD.name wasn't
defined, if the trigger was NOT an update.

OK, but the second case works??!?! Is this a weird peculiarity of the
pl/pgsql lazy evaluation rules? Why doesn't the first one work if the
second one does?

Chris

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kaz Kylheku 2004-11-15 07:41:21 Re: CVS should die
Previous Message Greg Stark 2004-11-15 07:00:37 Re: MAX/MIN optimization via rewrite (plus query rewrites