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
Syntax
concat_ws(sep, val1, val2, ...)
Parameters
| Parameter | Description |
|---|---|
sep |
The separator. |
val |
The values to join. |
Return value
Text, or NULL if sep is NULL.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 9.1 | Added |
In other languages
CONCAT_WS()· SQLite
Related
CONCAT()· Join any number of values into one string, treating NULL arguments as empty strings.STRING_AGG()· Join a group's non-NULL values into one string with a separator, optionally in a given ORDER BY order.- SQL String Functions · tutorial