Обсуждение: shortcircuit logic in plpsql

Поиск
Список
Период
Сортировка

shortcircuit logic in plpsql

От
Joseph Shraibman
Дата:
I'm trying to do this:

  IF TG_OP = \'INSERT\' OR (TG_OP = \'UPDATE\' AND OLD.status <>
NEW.status) THEN

..but pg is complaining:

ERROR:  record "old" is not assigned yet
DETAIL:  The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT:  PL/pgSQL function "set_dir_count" line 4 at if

Does plpgsql not short circuit its logic?

=>select version();
                                                  version
---------------------------------------------------------------------------------------------------------
  PostgreSQL 8.0.8 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.2
20030222 (Red Hat Linux 3.2.2-5)
(1 row)

Re: shortcircuit logic in plpsql

От
Tom Lane
Дата:
Joseph Shraibman <jks@selectacast.net> writes:
> Does plpgsql not short circuit its logic?

We make no guarantees about evaluation order.  In the particular
case at hand, you're losing because plpgsql has to evaluate all
the variables that it's going to pass into the SQL engine for
that expression.  Break it into two statements ...

            regards, tom lane