CONCAT_WS
Joins strings, inserting the given separator between them.
PostgreSQL 17.9
CONCAT_WS(separator, str[, ...])- [ ]optional part
- ...can be repeated
- separator
- Separator inserted between the stringstext
- 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.9
SELECT CONCAT_WS('-', '2024', '03', '08');Full name from three columns
PostgreSQL 17.9
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.