Marek Lewczuk <[EMAIL PROTECTED]> 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 ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings