Sqlite IFNULL () in postgres

What's the equivalent of SQLite IFNULL()

in Postgres?

I need to execute a query (sqlite in Ruby):

SELECT ifnull(max(code_id) + 1, 1) 
FROM configentries 
WHERE configtable_id = ...

      

What would it look like if I want to get the same result with PostgreSQL?

+3


source to share


1 answer


try coalesce

:

The COALESCE function returns the first of its arguments, which is not zero. Null is returned only if all arguments are null



sql = "SELECT coalesce(max(code_id) + 1, 1) FROM configentries WHERE configtable_id = " + table_id

      

+7


source







All Articles