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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marek Lewczuk <newsy(at)lewczuk(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, Alexander Litvinov <lan(at)ac-sw(dot)com>, Lista dyskusyjna pgsql-general <pgsql-general(at)postgresql(dot)org>, Lista dyskusyjna pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: [GENERAL] CASE in where statement. BUG ??
Date: 2003-12-19 15:40:39
Message-ID: 9626.1071848439@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Marek Lewczuk <newsy(at)lewczuk(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Rich Hall 2003-12-19 15:45:07 Re: plpgsql Integer Concat To String
Previous Message Russell Garrett 2003-12-19 13:32:55 Re: Urgent: Key constraints behaving weirdly

Browse pgsql-general by date

  From Date Subject
Next Message Lynn.Tilby 2003-12-19 16:58:05 7.1.3 ecpg answered BUT...
Previous Message D. Dante Lorenso 2003-12-19 14:52:52 Re: How to navigate tree without CONNECT BY?