CONCAT_WS
Joins strings, inserting the given separator between them.
PostgreSQL 17.5
CONCAT_WS(separator, str[, ...])Parameters
- separatortext
- Separator inserted between the strings
- str
- String to join
Return value
A string; NULL arguments are skipped, but a NULL separator gives NULL
Examples
Date from parts with hyphens
PostgreSQL 17.5
SELECT CONCAT_WS('-', '2024', '03', '08');Full name from three columns
PostgreSQL 17.5
SELECT CONCAT_WS(' ', last_name, first_name, middle_name) AS full_name
FROM Teacher;Details
Empty strings are not skipped, and the separator is placed around them too: CONCAT_WS('-', 'a', '', 'b') returns a--b.