On this page
is_aggregate_function: COUNT SUM AVG MIN MAX STRING_AGG ARRAY_AGG JSON_AGG JSONB_AGG JSON_OBJECT_AGG JSONB_OBJECT_AGG JSON_ARRAYAGG JSON_OBJECTAGG (crates/executor/src/catalog_fn.rs).
SELECT count(*), count(email), count(DISTINCT city) FROM users;
SELECT sum(total), avg(total), min(total), max(total) FROM orders;
SELECT string_agg(name, ', ' ORDER BY name), array_agg(id ORDER BY id) FROM users;
SELECT json_agg(payload), jsonb_agg(payload), json_object_agg(name, id) FROM users;
SELECT user_id, count(*) FROM orders GROUP BY user_id HAVING count(*) > 1;
SELECT a, b, count(*) FROM t GROUP BY GROUPING SETS ((a,b),(a),());
SELECT count(*) FILTER (WHERE total > 100) FROM orders;Behavior (query/aggregate.rs, join/aggregate.rs)#
COUNT(*)counts rows;COUNT(expr)skips NULL;COUNT(DISTINCT)dedups byto_sql_text(unifies1/1.0).SUM/AVG: int (Int8), exactNumeric,f64paths; empty → NULL;AVG(int)→ normalizedNumeric(PG typing).MIN/MAXviavalue_cmp, NULL skipped, empty → NULL.JSON_AGGkeeps per-row values incl. SQL NULL→JSON null;JSON_OBJECT_AGGskips NULL keys.- Modifiers:
DISTINCT(fully distinct-aware forCOUNT),FILTER (WHERE …),agg(x ORDER BY … [NULLS FIRST|LAST]). - Bare
SELECT COUNT(*)withoutWHEREanswered by key count.
General engine trigger: string_agg/array_agg/json_*agg, non-column GROUP BY, multi-sets, or GROUP BY+ORDER BY.
Was this page helpful? Thanks — noted locally, nothing is sent anywhere.