X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id C4AE49FB3A1 for ; Thu, 7 Sep 2006 01:11:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 14280-02-9 for ; Thu, 7 Sep 2006 01:11:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 991119F9ECD for ; Thu, 7 Sep 2006 01:10:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k874AISX028986; Thu, 7 Sep 2006 00:10:18 -0400 (EDT) To: Daniel CAUNE cc: pgsql-sql@postgresql.org Subject: Re: Evaluation of if conditions In-reply-to: <001601c6d204$5d2cd840$0b00a8c0@tedy> References: <001601c6d204$5d2cd840$0b00a8c0@tedy> Comments: In-reply-to Daniel CAUNE message dated "Wed, 06 Sep 2006 18:32:40 -0400" Date: Thu, 07 Sep 2006 00:10:18 -0400 Message-ID: <28985.1157602218@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.114 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/43 X-Sequence-Number: 26254 Daniel CAUNE 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