With a sample query such as

SELECT x, avg(x)
FROM (VALUES (1), (2), (3)) AS v (x);

We give the error message "column "v.x" must appear in the GROUP BY
clause or be used in an aggregate function".

This is correct but incomplete.  Attached is a trivial patch to also
suggest that the user might have been trying to use a window function.
-- 
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support
diff --git a/src/backend/parser/parse_agg.c b/src/backend/parser/parse_agg.c
index c745fcdd2b..52d9a3d00e 100644
--- a/src/backend/parser/parse_agg.c
+++ b/src/backend/parser/parse_agg.c
@@ -1402,7 +1402,7 @@ check_ungrouped_columns_walker(Node *node,
 		if (context->sublevels_up == 0)
 			ereport(ERROR,
 					(errcode(ERRCODE_GROUPING_ERROR),
-					 errmsg("column \"%s.%s\" must appear in the GROUP BY clause or be used in an aggregate function",
+					 errmsg("column \"%s.%s\" must appear in the GROUP BY clause or be used in an aggregate or window function",
 							rte->eref->aliasname, attname),
 					 context->in_agg_direct_args ?
 					 errdetail("Direct arguments of an ordered-set aggregate must use only grouped columns.") : 0,

Reply via email to