Odd plpgsql behaviour - Mailing list pgsql-hackers

From Christopher Kings-Lynne
Subject Odd plpgsql behaviour
Date
Msg-id 419856D8.3000205@familyhealth.com.au
Whole thread Raw
Responses Re: Odd plpgsql behaviour  (Mike Rylander <mrylander@gmail.com>)
List 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


pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: MAX/MIN optimization via rewrite (plus query rewrites
Next
From: Dawid Kuroczko
Date:
Subject: Re: MAX/MIN optimization via rewrite (plus query rewrites