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
?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communitythe problem is - use 0 as CASE, 0 == false so query compare:
try to change query:
SELECT
CASE 3
WHEN TRUE THEN
'c'
WHEN 'true1222' THEN
'a'
ELSE
'b'
END;
and it return expected - 'b'
'true1222'
was converted to numeric for comparison with 0
. A string without leading digits converts to 0
.
Nov 4, 2016 at 4:06