I usq sqlite3 (on Android) and try to return a default value, if a select has to handle NULL values.
Normally this works:
SELECT ifnull(NULL, 12);
12
With a variable:
SELECT ifnull(var, 21) from (select NULL as var);
21
But the moment I use a table and this table is empty, then I don’t get anything:
SELECT ifnull(_id, 1) FROM empty_table;
<nothing here>
Even returning a simple number is not possible:
SELECT 123;
123
SELECT 234 FROM empty_table;
<nothing here>
Why does that happen? How can I still get a value out of it?
It’s a bit different.
When using SELECT with rows, ifnull() is evaluated once per row, so you need at least one row.
You could probably try something: