Re: PL/PGSQL: why IF test the whole condition before failing or not? - Mailing list pgsql-general

From Tom Lane
Subject Re: PL/PGSQL: why IF test the whole condition before failing or not?
Date
Msg-id 4959.1250631268@sss.pgh.pa.us
Whole thread Raw
In response to PL/PGSQL: why IF test the whole condition before failing or not?  (Suporte PK <fknoedt@gmail.com>)
List pgsql-general
Suporte PK <fknoedt@gmail.com> writes:
> IF TG_OP = 'UPDATE' AND OLD.field != NEW.field THEN
> ...
> The question is: if the trigger was not fired by an UPDATE event,
> shouldn't it make the first test and then ignore the rest of the condition?

No.  This is a very very common error.  The behavior is not as
short-circuity as you'd think.  Break it into two IFs.

            regards, tom lane

pgsql-general by date:

Previous
From: Suporte PK
Date:
Subject: PL/PGSQL: why IF test the whole condition before failing or not?
Next
From: Tom Lane
Date:
Subject: Re: Any justification for sequence table vs. native sequences?