pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel CAUNE <d.caune@free.fr>
Cc: pgsql-sql@postgresql.org
Subject: Re: Evaluation of if conditions
Date: Thu, 07 Sep 2006 00:10:18 -0400
Message-ID: <28985.1157602218@sss.pgh.pa.us> (raw)
In-Reply-To: <001601c6d204$5d2cd840$0b00a8c0@tedy>
References: <001601c6d204$5d2cd840$0b00a8c0@tedy>

Daniel CAUNE <d.caune@free.fr> writes:
> 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

It's not that all the conditions get evaluated by an OR, it's that
plpgsql needs to send all the parameter values that the IF-expression
needs down to the core SQL engine.  So it fails on "OLD.bar" not being
defined, long before the expression evaluator gets to think about
whether TG_OP = 'INSERT' or not.

So, yeah, you want to rewrite it as two separate IF-tests.

			regards, tom lane



view thread (5+ messages)

Message-ID: <28985.1157602218@sss.pgh.pa.us>
Permalink:  ../28985.1157602218@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28985.1157602218@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, d.caune@free.fr
  Subject: Re: Evaluation of if conditions
  In-Reply-To: <28985.1157602218@sss.pgh.pa.us>

* 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