Skip to main content
Concatenates non-NULL string values from a group into a single string, with each value separated by the specified delimiter.

Syntax

Parameters

Return Type

TEXT

Remarks

  • NULL values in <expression> are silently skipped.
  • If all input values are NULL, or if the input set is empty, STRING_AGG returns NULL.
  • No specific order for the concatenation of values is guaranteed. To concatenate in a specific order, use ARRAY_AGG, ARRAY_SORT, and ARRAY_TO_STRING.
  • An empty <delimiter> (empty string '') concatenates values without any separator.

Example

The levels table contains the following values:

Rows: 10Execution time: 5.13ms

The following example concatenates all level names within each leveltype, separated by commas:

Rows: 3Execution time: 10.18ms

The following example shows that NULL values are skipped:

Rows: 1Execution time: 3.82ms