MySQL IFNULL() to PostgreSQL COALESCE() Crosswalk
PostgreSQL's COALESCE() covers everything MySQL's IFNULL() does for the common 2-argument case, and goes further by accepting any number of fallback expressions.
Close equivalent Covers the common case, but has documented behavioral differences.
- MySQL feature
IFNULL()- PostgreSQL equivalent
COALESCE()
Main limitation: IFNULL() takes exactly two arguments; COALESCE() accepts any number and returns the first non-null one. For a straight 2-argument port they behave identically, but COALESCE's variadic form lets you flatten nested IFNULL() calls into one expression.
Quick mapping
| MySQL | IFNULL() |
|---|---|
| PostgreSQL | COALESCE() |
Examples
Fallback for a NULL column value
SELECT IFNULL(nickname, username) AS display_name FROM users; SELECT COALESCE(nickname, username) AS display_name FROM users; Chaining multiple fallbacks
SELECT IFNULL(nickname, IFNULL(username, 'Anonymous')) FROM users; SELECT COALESCE(nickname, username, 'Anonymous') FROM users; Caveats
Caveat
IFNULL() takes exactly two arguments; COALESCE() accepts any number and returns the first non-null one. For a straight 2-argument port they behave identically, but COALESCE's variadic form lets you flatten nested IFNULL() calls into one expression.
Caveat
MySQL's IFNULL() determines its result type from the two argument types using MySQL-specific coercion rules; PostgreSQL's COALESCE() requires all arguments to share (or be coercible to) one type up front, so mixing incompatible types errors in PostgreSQL where MySQL might silently convert.
Caveat
COALESCE() is ANSI SQL standard and behaves identically across PostgreSQL, SQL Server, and Oracle; IFNULL() is MySQL-specific — SQL Server's nearest equivalent is ISNULL(), a different name again with only 2-argument support.
References
- MySQL Reference Manual — IFNULL() (v8.4) — checked 2026-07-29
- PostgreSQL docs — COALESCE (v17) — checked 2026-07-29
Last verified 2026-07-29.