Read more

MySQL: CONCAT with NULL fields

Tobias Kraze
October 29, 2010Software engineer at makandra GmbH

In MySQL,

CONCAT('foo', 'bar', NULL) = NULL
Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
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)