Re: Evaluation of if conditions
От | Tom Lane |
---|---|
Тема | Re: Evaluation of if conditions |
Дата | |
Msg-id | 28985.1157602218@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Evaluation of if conditions (Daniel CAUNE <d.caune@free.fr>) |
Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: