pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gregory S. Williamson <gsw@globexplorer.com>
To: Daniel CAUNE <d.caune@free.fr>
To: pgsql-sql@postgresql.org
Subject: Re: Evaluation of if conditions
Date: Wed, 6 Sep 2006 16:02:30 -0700
Message-ID: <71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net> (raw)
References: <001601c6d204$5d2cd840$0b00a8c0@tedy>

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@postgresql.org 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 gsw@globexplorer.com
"https://mailscanner.globexplorer.com/dspam/dspam.cgi?signatureID=44ff5167171391789821027&user=gs...;
!DSPAM:44ff5167171391789821027!
-------------------------------------------------------








view thread (5+ messages)  latest in thread

Message-ID: <71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net>
Permalink:  ../71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net/
Also on:    postgresql.org/message-id/71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: gsw@globexplorer.com, d.caune@free.fr
  Subject: Re: Evaluation of if conditions
  In-Reply-To: <71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net>
  References: <001601c6d204$5d2cd840$0b00a8c0@tedy> <71E37EF6B7DCC1499CEA0316A256832802B3E511@loki.wc.globexplorer.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox