LISTAGG

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Concatenates the input values from a group into a single string, separated by a delimiter, in the order that you specify.

  • <value>: The string expression to concatenate.
  • <separator>: A constant string placed between concatenated values. It must be a literal constant, not a computed expression. Pass NULL::text (or '') to concatenate with no separator.
  • DISTINCT: Concatenates only distinct values. When you use DISTINCT, the ORDER BY expression (including its collation) must match <value>.
  • WITHIN GROUP (ORDER BY <sort_expression> [, ...]): Orders the values before concatenation. Each sort key accepts ASC / DESC and NULLS FIRST / NULLS LAST.

A string containing the concatenated values.

Null handling:

  • NULL inputs are always skipped and contribute no separator.
  • A group whose values are all NULL returns NULL.
  • Empty-string values are preserved and contribute separators (they aren’t treated as NULL).
  • The separator must be a constant. A computed separator such as concat('-', '-') raises an error.
  • LISTAGG requires string arguments; binary (bytes) values aren’t supported.
  • LISTAGG supports the FILTER clause to restrict which rows feed the aggregate.
  • If no ORDER BY is specified, the resulting string contains the entries in an implementation-defined, non-deterministic order.
  • LISTAGG with WITHIN GROUP (ORDER BY …) isn’t supported in combination with ROLLUP, CUBE, or GROUPING SETS. Unordered LISTAGG (no WITHIN GROUP) is supported with all of those.
  • LISTAGG is equivalent to ARRAY_TO_STRING applied to ARRAY_AGG. Use ARRAY_AGG when you need an array rather than a delimited string.

Concatenate x values in ascending order. The NULL input is skipped.

Returns a,b.

Build a comma-separated list of tags for each account.

Compute two independently filtered concatenations in a single query.