SQLSTATE 42803Severity lowLab verified

Incident brief

Column must appear in GROUP BY

A non-aggregated column in the SELECT list of a grouped query must appear in GROUP BY or be wrapped in an aggregate; otherwise PostgreSQL raises this grouping error.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Column must appear in GROUP BY
What triggers it
Write a GROUP BY query that selects a column which is neither grouped nor aggregated.
The fix
Wrap the column in an aggregate (SUM, MAX, ...).
Proof
Reproduced on PostgreSQL 18.4 → A single query reproduces SQLSTATE 42803; the ungrouped column is rejected and the LINE points at it.

The fix

What to do right now

The immediate, application-level response to this error.

  • Wrap the column in an aggregate (SUM, MAX, ...).
  • Or add the column to the GROUP BY clause if you meant to group by it.
Fix — SQL
-- Aggregate the column (or add it to GROUP BY).
SELECT customer_id, sum(amount) FROM sales_line GROUP BY customer_id;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed