MySQL coalesce two nullable BITs gives result =48

204 views Asked by At

I have a query with two nullable bit flag columns and I would like to coalesce those in result set into single flag:

COALESCE(flagA, flagB) as FlagAB

however for column values null, false the result is 48 rather than false which is rather unexpected. Playground example (also on db fiddle):

create table Flags (flagA bit null, flagB bit null);
insert into Flags  (flagA, flagB) values (null, false);

select *, COALESCE(flagA, flagB) as FlagAB from Flags;

output:

| FlagA | FlagB | FlagAB |
--------------------------
| null  | 0     | 48     |

What is going on and how can I fix the query so that it returns correctly coalesced flag?

0

There are 0 answers