scribase
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.

Other class 42 errors

  • 42501 permission denied for table x / new row violates row-level security policy for table "x"
  • 42601 syntax error at or near "x"
  • 42P01 relation "x" does not exist
  • 42P07 relation "x" already exists
  • 42P05 prepared statement "s0" already exists
  • 42703 column "x" does not exist