---
title: "PostgREST Aggregate Functions"
description: "PostgREST v12 adds on-the-fly aggregate functions (avg, count, max, min, sum) to its API."
url: "https://swe.quest/articles/postgrest-aggregate-functions-f622df6532444e20"
canonical: "https://supabase.com/blog/postgrest-aggregate-functions"
source: "Supabase"
published: "2024-02-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["postgres","api-design","sql"]
---

# PostgREST Aggregate Functions

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2024-02-29, 7 min read, How-to. Original: [https://supabase.com/blog/postgrest-aggregate-functions](https://supabase.com/blog/postgrest-aggregate-functions)

## Summary

PostgREST v12 adds on-the-fly aggregate functions (avg, count, max, min, sum) to its API. You apply them by appending the function to a column in the select parameter, and any non-aggregated columns become implicit GROUP BY columns. Aggregates compose with column renaming, filtering, embedded resources and spread relationships, so you can group movies by a related director's country, for example. Because aggregates bypass pagination limits and can be abused for denial of service, the feature is disabled by default. Before enabling it, set per-role query cost ceilings with pg\_plan\_filter.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL aggregate functions and GROUP BY ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- PostgREST basics

## Keywords

PostgREST, PostgreSQL, Supabase, supabase-js, pg\_plan\_filter

## Related posts

- [PostgREST 11 pre-release](https://swe.quest/articles/postgrest-11-pre-release-708e03106b6a485f.md): Supabase · 2022-12-16 · Medium · 3 min read · PostgreSQL, API design, SQL
  PostgREST 11's pre-release, available through the Supabase CLI, adds three querying features.
- [What is new in PostgREST v11.1?](https://swe.quest/articles/what-is-new-in-postgrest-v11-1-2bc974a578068114.md): Supabase · 2023-07-12 · Medium · 5 min read · PostgreSQL, API design, Consistency models, SQL
  PostgREST 11.1 lets impersonated JWT roles (anon, authenticated, service\_role) carry Postgres settings via ALTER ROLE ...
- [SQL or NoSQL? Why not use both (with PostgreSQL)?](https://swe.quest/articles/sql-or-nosql-why-not-use-both-with-postgresql-98c239e2ff7e761c.md): Supabase · 2022-11-24 · Medium · 12 min read · PostgreSQL, SQL, Databases
  PostgreSQL's JSONB columns let an app store nested, variable-length data (here, a daily food, water and exercise log) as a single row instead of spreading it across several normalized tables, while keeping SQL available for analysis.
- [PostgREST 9](https://swe.quest/articles/postgrest-9-20b92866c21e13eb.md): Supabase · 2021-11-27 · Medium · 2 min read · PostgreSQL, API design
  PostgREST 9 adds inner-join resource embedding via the \`!inner\` keyword, so top-level rows can be filtered by conditions on an embedded table (e.g. messages filtered by users.username).
- [PostgREST 13](https://swe.quest/articles/postgrest-13-412584efa365a837.md): Supabase · 2025-09-30 · Medium · 3 min read · PostgreSQL, API design, Search, Identity & auth
  PostgREST 13 adds spread syntax for to-many relationships so one-to-many and many-to-many joins can be returned as flat JSON arrays, automatic to\_tsvector conversion that enables full text search on text and json/jsonb columns (backed by a GIN index on the expression), and a maxAffected limit that throws an error when an update, delete or rpc touches too many rows.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
