Read more

MySQL: CONCAT with NULL fields

Tobias Kraze
October 29, 2010Software engineer at makandra GmbH

In MySQL,

CONCAT('foo', 'bar', NULL) = NULL
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)