Index: src/backend/parser/parse_agg.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/parser/parse_agg.c,v retrieving revision 1.52 diff -u -r1.52 parse_agg.c --- src/backend/parser/parse_agg.c 2003/04/03 18:04:09 1.52 +++ src/backend/parser/parse_agg.c 2003/04/30 20:39:29 @@ -34,6 +34,8 @@ static bool check_ungrouped_columns_walker(Node *node, check_ungrouped_columns_context *context); +bool force_targets_grouped = true; + /* * check_ungrouped_columns - * Scan the given expression tree for ungrouped variables (variables @@ -246,13 +248,21 @@ (Node *) groupClauses); /* - * Check the targetlist and HAVING clause for ungrouped variables. + * Check the targetlist clause for ungrouped variables. */ - clause = (Node *) qry->targetList; - if (hasJoinRTEs) - clause = flatten_join_alias_vars(qry, clause); - check_ungrouped_columns(clause, pstate, - groupClauses, have_non_var_grouping); + + if (force_targets_grouped) + { + clause = (Node *) qry->targetList; + if (hasJoinRTEs) + clause = flatten_join_alias_vars(qry, clause); + check_ungrouped_columns(clause, pstate, + groupClauses, have_non_var_grouping); + } + + /* + * Check the HAVING clause for ungrouped variables. + */ clause = (Node *) qry->havingQual; if (hasJoinRTEs) Index: src/backend/utils/misc/guc.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/guc.c,v retrieving revision 1.119 diff -u -r1.119 guc.c --- src/backend/utils/misc/guc.c 2003/04/25 19:45:09 1.119 +++ src/backend/utils/misc/guc.c 2003/04/30 20:39:31 @@ -43,6 +43,7 @@ #include "optimizer/paths.h" #include "optimizer/prep.h" #include "parser/parse_expr.h" +#include "parser/parse_agg.h" #include "storage/fd.h" #include "storage/freespace.h" #include "storage/lock.h" @@ -533,6 +534,10 @@ { {"transaction_read_only", PGC_USERSET, GUC_NO_RESET_ALL}, &XactReadOnly, false, NULL, NULL + }, + { + {"force_targets_grouped", PGC_USERSET, GUC_NO_RESET_ALL}, &force_targets_grouped, + true, NULL, NULL }, { Index: src/backend/utils/misc/postgresql.conf.sample =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/postgresql.conf.sample,v retrieving revision 1.77 diff -u -r1.77 postgresql.conf.sample --- src/backend/utils/misc/postgresql.conf.sample 2003/04/19 00:37:28 1.77 +++ src/backend/utils/misc/postgresql.conf.sample 2003/04/30 20:39:31 @@ -219,3 +219,4 @@ #statement_timeout = 0 # 0 is disabled, in milliseconds #db_user_namespace = false #preload_libraries = '' +#force_targets_grouped = true Index: src/bin/psql/tab-complete.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/tab-complete.c,v retrieving revision 1.76 diff -u -r1.76 tab-complete.c --- src/bin/psql/tab-complete.c 2003/04/03 20:18:16 1.76 +++ src/bin/psql/tab-complete.c 2003/04/30 20:39:31 @@ -522,6 +522,7 @@ "enable_tidscan", "explain_pretty_print", "extra_float_digits", + "force_targets_grouped", "from_collapse_limit", "fsync", "geqo", Index: src/include/parser/parse_agg.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/parser/parse_agg.h,v retrieving revision 1.25 diff -u -r1.25 parse_agg.h --- src/include/parser/parse_agg.h 2003/01/17 03:25:04 1.25 +++ src/include/parser/parse_agg.h 2003/04/30 20:39:32 @@ -17,4 +17,6 @@ extern void parseCheckAggregates(ParseState *pstate, Query *qry); +extern bool force_targets_grouped; + #endif /* PARSE_AGG_H */