Re: PL/PGSQL: why IF test the whole condition before failing or not?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Suporte PK <fknoedt(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PL/PGSQL: why IF test the whole condition before failing or not?
Date: 2009-08-18 21:34:28
Message-ID: 4959.1250631268@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Suporte PK <fknoedt(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2009-08-18 21:38:19 Re: index "pg_authid_rolname_index" is not a btree
Previous Message Suporte PK 2009-08-18 21:23:42 PL/PGSQL: why IF test the whole condition before failing or not?