Skip to main content

STRING_AGG

Aggregate function.

The STRING_AGG() function converts all the non-NULL values of a column to String, separated by the delimiter.

Syntax

STRING_AGG(expression)
STRING_AGG(expression, delimiter)

Arguments

ArgumentsDescription
expressionAny String expression
delimiterOptional constant String, if not specified, use empty String

Return Type

the String type

Examples

CREATE TABLE aggr(a string null);

INSERT INTO aggr VALUES
('abc'),
('def'),
(null),
('xyz');

SELECT string_agg(a) FROM aggr;
+---------------+
| string_agg(a) |
+---------------+
| abcdefxyz |
+---------------+

SELECT string_agg(a, '|') FROM aggr;
+--------------------+
| string_agg(a, '|') |
+--------------------+
| abc|def|xyz |
+--------------------+