0

The following case expression results in a,

select case 0 when true  then 'c' when 'true1222' then 'a' else 'b' end;  

Anyone knows why? How could 0 be equal to true1222?

1 Answer 1

1

the problem is - use 0 as CASE, 0 == false so query compare:

  • TRUE - not, go forward
  • 'true1222' - FALSE == 0, OK

try to change query:

SELECT
    CASE 3
WHEN TRUE THEN
    'c'
WHEN 'true1222' THEN
    'a'
ELSE
    'b'
END;

and it return expected - 'b'

1
  • Perhaps also, 'true1222' was converted to numeric for comparison with 0. A string without leading digits converts to 0.
    – Rick James
    Nov 4, 2016 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.