The following query yields an error
select 1 where case null when null then true when true then true else false end
ERROR: operator does not exist: text = boolean
What is the correct way to perform a nullable boolean value check in the WHERE clause?
Udate
Suprisingly this one works fine
create table d (id serial, v boolean);
insert into d(v) values(null),(true),(false);
select id from d where case v when null then true when v then true else true end;
id
----
1
2
3
(3 rows)
PS: actually this does not work either because the null value is casted to boolean and hence else is triggered instead of when null.
nullastruewhy not simply usewhere v or v is null?where $1 is null or $1? with$1being the parameter. Or better: only append the condition if the parameter is not nullcaseapproach but your alternative solution suits my case better. thank you!