Read more

MySQL: CONCAT with NULL fields

Tobias Kraze
October 29, 2010Software engineer at makandra GmbH


CONCAT('foo', 'bar', NULL) = NULL
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show snapshot

the NULL always wins in MySQL.

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

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


In PostgreSQL the NULL is not viral in CONCAT:

CONCAT('foo', 'bar', NULL) = 'foobar'
Posted by Tobias Kraze to makandra dev (2010-10-29 11:39)