Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canonical way to map null->false

Tags:

sql

What is a canonical expression for the following:

NULL  -> false
false -> false
true  -> true

What I am using is:

select (foo is not null and foo)

which seems to work fine, but I'm wondering if there is a standard convention for this.

like image 917
gcbenison Avatar asked Sep 16 '25 22:09

gcbenison


2 Answers

select coalesce(foo, false) from table
like image 117
chue x Avatar answered Sep 19 '25 12:09

chue x


I just looked it up. COALESCE() is ansi SQL. So SELECT (foo, false) would give foo or false.

like image 32
dnagirl Avatar answered Sep 19 '25 12:09

dnagirl