Changes

Difference MySQL PostGreSQL

579 bytes added, 10:29, 19 June 2014
no edit summary
END
</pre>
 
Alternatively, the built-in function COALESCE() can be used in PostgreSQL:
<pre>
SELECT COALESCE(field, 'N/A')
FROM table;
</pre>
 
This query will return the value of ''field'' if it is not null, or the string N/A if field is null. In general, COALESCE() returns the first value that is not null:
<pre>
SELECT COALESCE(field1, field2, field3, 'N/A')
FROM table;
</pre>
If field1 is null, this query will evaluate field2 -- if field2 is null, it will evaluate field3, etc. If all the provided fields are null, it will return the last provided value, in this case the string N/A.
=== Date manipulations ===__NOEDITSECTION__
1,068
edits