Skip to content
masterclass Buddy

PostgreSQL · Function

array_agg

array_agg collects input values, including nulls, into an array. You can control the element order with ORDER BY inside the aggregate call.

Last updated

Syntax

array_agg(anynonarray ORDER BY input_sort_columns) → anyarray
array_agg(anyarray ORDER BY input_sort_columns) → anyarray

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • coalesce
  • array_to_string
  • array_upper
  • string_to_array
  • unnest

Source: PostgreSQL: Documentation: 18: 9.21. Aggregate Functions. Checked 2026-11-03.