Re: Evaluation of if conditions

From: "Gregory S(dot) Williamson" <gsw(at)globexplorer(dot)com>
To: "Daniel CAUNE" <d(dot)caune(at)free(dot)fr>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Evaluation of if conditions
Date: 2006-09-06 23:02:30
Message-ID: 71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Daniel,

AFAIK there is no short-circuiting of evaluations in postgres and I don't think you can depend on the order they appear in to determine the order in which they are checked, although more knowledgable people may have better info than I ... so the rewritten form is the way to go.

Greg Williamson
DBA
GlobeXplorer LLC

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org on behalf of Daniel CAUNE
Sent: Wed 9/6/2006 3:32 PM
To: pgsql-sql(at)postgresql(dot)org
Cc:
Subject: [SQL] Evaluation of if conditions

Hi,

How does the IF statement evaluate conditions? Does it evaluate conditions
following their declaration order from left to right? In case of
or-conditions, does the IF statement stop evaluating conditions whenever a
first or-condition is true?

The following snippet seems to be invalid, which let me think that PL/PGSQL
evaluates all the conditions:

IF (TG_OP = 'INSERT') OR
(OLD.bar = ...) THEN
statement
END IF;

Should be rewritten as (for example):

IF (TG_OP = 'INSERT') THEN
statement
ELSIF (OLD.bar = ...) THEN
statement
END IF;

Regards,

--
Daniel

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

-------------------------------------------------------
Click link below if it is SPAM gsw(at)globexplorer(dot)com
"https://mailscanner.globexplorer.com/dspam/dspam.cgi?signatureID=44ff5167171391789821027&user=gsw(at)globexplorer(dot)com&retrain=spam&template=history&history_page=1"
!DSPAM:44ff5167171391789821027!
-------------------------------------------------------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Oisin Glynn 2006-09-06 23:04:36 Re: Evaluation of if conditions
Previous Message Daniel CAUNE 2006-09-06 22:32:40 Evaluation of if conditions