Read more

MySQL: CONCAT with NULL fields

Tobias Kraze
October 29, 2010Software engineer at makandra GmbH

In MySQL,

CONCAT('foo', 'bar', NULL) = NULL
Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

the NULL always wins in MySQL.

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

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

PostgreSQL

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)