Check out our free eBook: "Best Practices for Optimizing Postgres Query Performance"Download Now

U118: Column must appear in the GROUP BY clause

Category: Application / User Errors
SQLSTATE: 42803 (Class 42 — Syntax Error or Access Rule Violation: grouping_error)
Urgency: low

Example Postgres Log Output:

ERROR: column "identifier_column.value_column" must appear in the GROUP BY clause or be used in an aggregate function at character 8
STATEMENT: SELECT identifier_column, MAX(value_column) FROM my_table

Explanation:

This error occurs since you've specified an aggregate function (e.g. MAX(...)) alongside a regular column in the query's target list, but you didn't specify the regular column as one of the columns to be grouped by.

Usually you would encounter this whilst testing on a development/staging system, or when mistyping a one-off query on a production system.

Recommended Action:

Be aware of GROUP BY and aggregation logic in PostgreSQL and be sure to specify the correct columns to aggregate by.

Learn More:


Couldn't find what you were looking for or want to talk about something specific?
Start a conversation with us →