PostgreSQL 18 reference · String Functions

PostgreSQL CONCAT_WS() Function

Join values with a separator between them, skipping NULLs. The first argument is the separator.

PostgreSQL 18 Since 9.1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

concat_ws(sep, val1, val2, ...)

Parameters

ParameterDescription
sep The separator.
val The values to join.

Return value

Text, or NULL if sep is NULL.

Examples

Join with a separator
SELECT concat_ws(', ', name, city, country) AS address
FROM customers
WHERE customer_id IN (1, 7);

Output

         address
--------------------------
 Ada Lovelace, London, UK
 Barbara Liskov, USA
(2 rows)

Run this on your computer — see “Get Started” for setup.

Numbers too
SELECT concat_ws('/', 2026, 3, 9) AS path;

Output

   path
----------
 2026/3/9
(1 row)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 9.1Added

In other languages

Was this page helpful?