CONCAT_WS(...)
All functions > STRING > CONCAT_WS(...)
Returns a concatenated string from a list of strings with a separator between each element.
Syntax
CONCAT_WS(separator, string, string, …) · CONCAT_WS_FN(separator, ARRAY[…])
Function form
Returns: Joined string
CONCAT_WS_FN(separator: VARCHAR, strings: ARRAY(VARCHAR)) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
separator | VARCHAR | Yes | Delimiter inserted between non-omitted elements |
strings | ARRAY(VARCHAR) | Yes | Strings to join in order |
Notes
- Separator is inserted only between non-omitted pieces; skipped NULLs do not add an extra separator
- An empty argument list (after bundling) yields an empty string—no leading or trailing separator
- Variadic form: every string argument must be
VARCHAR(bareNULLfails inference—useNULL(VARCHAR)or build anARRAY[...]and useCONCAT_WS_FN) NULLentries in the list are skipped (unlikeCONCAT, where aNULLpiece makes the resultNULL); useCOALESCEwhen you need empty segments with separators
Examples
CONCAT_WS(...)
FeatureQL
RETURN
-- Dash between pieces
f1 := CONCAT_WS('-', 'A', 'B', 'C'),
-- Comma and space
f2 := CONCAT_WS(', ', 'Apple', 'Banana')
;Result
| f1 VARCHAR | f2 VARCHAR |
|---|---|
| A-B-C | Apple, Banana |
Edge cases
FeatureQL
RETURN
-- NULL piece omitted; no extra delimiter gap
f1 := CONCAT_WS('-', 'A', NULL::VARCHAR, 'B')
;Result
| f1 VARCHAR |
|---|
| A-B |
CONCAT_WS_FN(...)
FeatureQL
RETURN
-- Separator and array of strings
f1 := CONCAT_WS_FN('-', ARRAY('A', 'B', 'C')),
-- Comma–space delimiter
f2 := CONCAT_WS_FN(', ', ARRAY('Apple', 'Banana'))
;Result
| f1 VARCHAR | f2 VARCHAR |
|---|---|
| A-B-C | Apple, Banana |
CONCAT_WS_FN — Edge cases
FeatureQL
RETURN
-- Single-space separator
f1 := CONCAT_WS_FN(' ', ARRAY('Hello', 'World')),
-- NULL element omitted
f2 := CONCAT_WS_FN('-', ARRAY('A', NULL::VARCHAR, 'B'))
;Result
| f1 VARCHAR | f2 VARCHAR |
|---|---|
| Hello World | A-B |