What is the PostgreSQL equivalent for ISNULL()

Byron Whitlock picture Byron Whitlock · Feb 6, 2010 · Viewed 263.2k times · Source

In MS SQL-Server, I can do:

SELECT ISNULL(Field,'Empty') from Table

But in PostgreSQL I get a syntax error. How do I emulate the ISNULL() functionality ?

Answer

Kyle Butt picture Kyle Butt · Feb 6, 2010
SELECT CASE WHEN field IS NULL THEN 'Empty' ELSE field END AS field_alias

Or more idiomatic:

SELECT coalesce(field, 'Empty') AS field_alias