PostgreSQL Concat if not Null

If you want to concat multiple values, but exclude the ones that are null, you can use the CONCAT_WS function.

The first argument is the delimiter and all the following values will be concated if they are not null.

SELECT CONCAT_WS(',', value1, value2, value3)


value1: Null
value2: 2
value3: 3
value4: Null

SELECT CONCAT_WS(',', value1, value2, value3, value4);
profile picture of the author

Jannik Rehkemper

I'm an professional Linux Administrator and Hobby Programmer. My training as an IT-Professional started in 2019 and ended in 2022. Since 2023 I'm working as an Linux Administrator.