sqlite IFNULL() in postgres
50,877
Solution 1
try coalesce
:
The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null
SELECT coalesce(max(code_id) + 1, 1)
FROM configentries
WHERE configtable_id = ...
Solution 2
Try this,
Select NULLIF(Max(code_id), 0) +1
from configentries
WHERE configtable_id = ...
Author by
nintschger
Updated on April 10, 2021Comments
-
nintschger about 3 years
What is the equivalent of SQLite's
IFNULL()
in Postgres?I have to following query (sqlite in Ruby):
SELECT ifnull(max(code_id) + 1, 1) FROM configentries WHERE configtable_id = ...
How should this look like if I want the same result with PostgreSQL?