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:   [EMAIL PROTECTED] on behalf of Daniel CAUNE
Sent:   Wed 9/6/2006 3:32 PM
To:     pgsql-sql@postgresql.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 [EMAIL PROTECTED]
"https://mailscanner.globexplorer.com/dspam/dspam.cgi?signatureID=44ff5167171391789821027&[EMAIL
 PROTECTED]&retrain=spam&template=history&history_page=1"
!DSPAM:44ff5167171391789821027!
-------------------------------------------------------






---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to