From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Daniel CAUNE <d(dot)caune(at)free(dot)fr> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Evaluation of if conditions |
Date: | 2006-09-07 04:10:18 |
Message-ID: | 28985.1157602218@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Daniel CAUNE <d(dot)caune(at)free(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Kaloyan Iliev | 2006-09-07 09:00:22 | Problem with FOR UPDATE |
Previous Message | Joe | 2006-09-06 23:40:17 | Re: Evaluation of if conditions |