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
ParameterTypeRequiredDescription
separatorVARCHARYesDelimiter inserted between non-omitted elements
stringsARRAY(VARCHAR)YesStrings 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 (bare NULL fails inference—use NULL(VARCHAR) or build an ARRAY[...] and use CONCAT_WS_FN)
  • NULL entries in the list are skipped (unlike CONCAT, where a NULL piece makes the result NULL); use COALESCE when 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 VARCHARf2 VARCHAR
A-B-CApple, 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 VARCHARf2 VARCHAR
A-B-CApple, 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 VARCHARf2 VARCHAR
Hello WorldA-B