Re: PL/PGSQL: why IF test the whole condition before failing or not?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PL/PGSQL: why IF test the whole condition before failing or not?
Дата
Msg-id 4959.1250631268@sss.pgh.pa.us
обсуждение исходный текст
Ответ на PL/PGSQL: why IF test the whole condition before failing or not?  (Suporte PK <fknoedt@gmail.com>)
Список pgsql-general
Suporte PK <fknoedt@gmail.com> writes:
> IF TG_OP = 'UPDATE' AND OLD.field != NEW.field THEN
> ...
> The question is: if the trigger was not fired by an UPDATE event,
> shouldn't it make the first test and then ignore the rest of the condition?

No.  This is a very very common error.  The behavior is not as
short-circuity as you'd think.  Break it into two IFs.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Suporte PK
Дата:
Сообщение: PL/PGSQL: why IF test the whole condition before failing or not?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Any justification for sequence table vs. native sequences?