postgres - CASE evaluates subexpression that is not needed to determine the result

From: Kamenoqd Zelen <kamenoqd(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: postgres - CASE evaluates subexpression that is not needed to determine the result
Date: 2018-11-05 13:07:05
Message-ID: CAJVAX4iRStCBv6wziJVDPOy6-fnhdALuxRnXodkBYenEN4m+Pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,
I have the following 3 examples of case expressions in postgres, which I
would expect to evaluate in the same way. However the first and the third
give ERROR: invalid input syntax for integer: "2017.7". The second one
returns true. Why is the difference?

Postgres documentation
<https://www.postgresql.org/docs/7.4/static/functions-conditional.html>
states:

"A CASE expression does not evaluate any subexpressions that are not needed
to determine the result."

select case when 0 = 0 then 1 < 2

when 0 = 2 then 2000 = ('2017.7')::bigint

end;

select case when 0 = 0 then 1 < 2

when 0 = 2 then 2000 = ('2017.7'||'')::bigint

end;

select case when (array[1,2])[1] =1 then 1 < 2

when (array[1,2])[1] = 2 then 2000 = ('2017.7'||'')::bigint

end;

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2018-11-05 13:50:00 Re: postgres - CASE evaluates subexpression that is not needed to determine the result
Previous Message Andres Freund 2018-11-05 08:46:07 Re: BUG #15486: PG11 jit on 50x slower than jit off