Re: [GENERAL] CASE in where statement. BUG ??

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [GENERAL] CASE in where statement. BUG ??
Дата
Msg-id 9626.1071848439@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [GENERAL] CASE in where statement. BUG ??  (Marek Lewczuk <newsy@lewczuk.com>)
Список pgsql-bugs
Marek Lewczuk <newsy@lewczuk.com> writes:
> Well, I must say that it is wird action... Why to check both elements of
> CASE expression, if we know for sure that only one will be executed ?

It cannot discover that the WHEN clause is constant-false until after it
has performed syntactic analysis --- which includes assigning datatypes
to all elements of the expression.

In theory perhaps we could do syntactic analysis of the WHEN part, then
stop and do constant-folding to see if we could prove that the WHEN is
always false before we move on to syntactic analysis of the THEN part.
In practice, no one does it that way --- it would arguably be illegal to
do so according to the SQL spec, which draws a very clear distinction
between parse-time checking and execution-time activity.  Early constant
folding would have unpleasant properties for user-defined functions,
too.  You might find that a change you make in one of your functions
doesn't show up in the behavior of some existing rule, because the call
to that function in the rule got constant-folded before the rule was
stored.

            regards, tom lane

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

Предыдущее
От: "Russell Garrett"
Дата:
Сообщение: Re: Urgent: Key constraints behaving weirdly
Следующее
От: Rich Hall
Дата:
Сообщение: Re: plpgsql Integer Concat To String