88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.54 2003/07/01 19:10 :52 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.55 2003/07/19 20:20 :52 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -69,7 +69,9 @@ transformAggregateCall(ParseState *pstate, Aggref *agg)
6969if (min_varlevel == 0 )
7070{
7171if (checkExprHasAggs ((Node * )agg -> target ))
72- elog (ERROR ,"aggregate function calls may not be nested" );
72+ ereport (ERROR ,
73+ (errcode (ERRCODE_GROUPING_ERROR ),
74+ errmsg ("aggregate function calls may not be nested" )));
7375}
7476
7577if (min_varlevel < 0 )
@@ -113,9 +115,13 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
113115 * problem is in WHERE.)
114116 */
115117if (checkExprHasAggs (qry -> jointree -> quals ))
116- elog (ERROR ,"Aggregates not allowed in WHERE clause" );
118+ ereport (ERROR ,
119+ (errcode (ERRCODE_GROUPING_ERROR ),
120+ errmsg ("aggregates not allowed in WHERE clause" )));
117121if (checkExprHasAggs ((Node * )qry -> jointree -> fromlist ))
118- elog (ERROR ,"Aggregates not allowed in JOIN conditions" );
122+ ereport (ERROR ,
123+ (errcode (ERRCODE_GROUPING_ERROR ),
124+ errmsg ("aggregates not allowed in JOIN conditions" )));
119125
120126/*
121127 * No aggregates allowed in GROUP BY clauses, either.
@@ -134,7 +140,9 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
134140if (expr == NULL )
135141continue ;/* probably cannot happen */
136142if (checkExprHasAggs (expr ))
137- elog (ERROR ,"Aggregates not allowed in GROUP BY clause" );
143+ ereport (ERROR ,
144+ (errcode (ERRCODE_GROUPING_ERROR ),
145+ errmsg ("aggregates not allowed in GROUP BY clause" )));
138146groupClauses = lcons (expr ,groupClauses );
139147if (!IsA (expr ,Var ))
140148have_non_var_grouping = true;
@@ -291,11 +299,15 @@ check_ungrouped_columns_walker(Node *node,
291299rte = rt_fetch (var -> varno ,context -> pstate -> p_rtable );
292300attname = get_rte_attribute_name (rte ,var -> varattno );
293301if (context -> sublevels_up == 0 )
294- elog (ERROR ,"Attribute %s.%s must be GROUPed or used in an aggregate function" ,
295- rte -> eref -> aliasname ,attname );
302+ ereport (ERROR ,
303+ (errcode (ERRCODE_GROUPING_ERROR ),
304+ errmsg ("attribute \"%s.%s\" must be GROUPed or used in an aggregate function" ,
305+ rte -> eref -> aliasname ,attname )));
296306else
297- elog (ERROR ,"Sub-SELECT uses un-GROUPed attribute %s.%s from outer query" ,
298- rte -> eref -> aliasname ,attname );
307+ ereport (ERROR ,
308+ (errcode (ERRCODE_GROUPING_ERROR ),
309+ errmsg ("sub-select uses un-GROUPed attribute \"%s.%s\" from outer query" ,
310+ rte -> eref -> aliasname ,attname )));
299311
300312}
301313