SQLSTATE 42803grouping_errorHTTP 400
Postgres error 42803: grouping error
column "x" must appear in the GROUP BY clause or be used in an aggregate function
A grouped query selects a column that is neither grouped nor aggregated.
Common causes
- Selecting extra columns next to count(*) or sum().
How to fix it
- Add the column to GROUP BY, wrap it in an aggregate (max, array_agg), or group by the primary key (Postgres then allows the other columns of that table).
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 400 for this error and returns the SQLSTATE in the code field of the JSON error body.
Questions
What does Postgres error 42803 mean?
42803 is grouping_error in class 42 (Syntax Error or Access Rule Violation). A grouped query selects a column that is neither grouped nor aggregated.
How do I fix 42803?
Add the column to GROUP BY, wrap it in an aggregate (max, array_agg), or group by the primary key (Postgres then allows the other columns of that table).
What HTTP status does a REST API return for 42803?
PostgREST, the REST layer behind supabase-js, answers 400.