MySQL: CONCAT with NULL fields


CONCAT('foo', 'bar', NULL) = NULL

the NULL always wins in MySQL.

If you would rather treat NULL as an empty string, use CONCAT_WS Archive (concatenation with separator) instead:

CONCAT_WS('', 'foo', 'bar', NULL) = 'foobar'


In PostgreSQL the NULL is not viral in CONCAT:

CONCAT('foo', 'bar', NULL) = 'foobar'
Tobias Kraze about 11 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more