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 ?
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 ?
Try:
Use
COALESCE()
instead:It functions much like
ISNULL
, although provides more functionality. Coalesce will return the first non null value in the list. Thus:returns 5, while
returns 2
Coalesce will take a large number of arguments. There is no documented maximum. I tested it will 100 arguments and it succeeded. This should be plenty for the vast majority of situations.
Or more idiomatic:
Create the following function
And it'll work.
You may to create different versions with different parameter types.