1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Implement outer-level aggregates to conform to the SQL spec, with

extensions to support our historical behavior.  An aggregate belongs
to the closest query level of any of the variables in its argument,
or the current query level if there are no variables (e.g., COUNT(*)).
The implementation involves adding an agglevelsup field to Aggref,
and treating outer aggregates like outer variables at planning time.
This commit is contained in:
Tom Lane
2003-06-06 15:04:03 +00:00
parent 2c93861f7c
commit e649796f12
26 changed files with 607 additions and 229 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.272 2003/05/28 16:03:56 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.273 2003/06/06 15:04:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1593,7 +1593,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt,
elog(ERROR, "Rule WHERE condition may not contain references to other relations");
/* aggregates not allowed (but subselects are okay) */
if (contain_agg_clause(stmt->whereClause))
if (pstate->p_hasAggs)
elog(ERROR, "Rule WHERE condition may not contain aggregate functions");
/* save info about sublinks in where clause */
@ -1808,7 +1808,7 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
qry->hasSubLinks = pstate->p_hasSubLinks;
qry->hasAggs = pstate->p_hasAggs;
if (pstate->p_hasAggs || qry->groupClause || qry->havingQual)
if (pstate->p_hasAggs || qry->groupClause)
parseCheckAggregates(pstate, qry);
if (stmt->forUpdate != NIL)
@ -2013,7 +2013,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
qry->hasSubLinks = pstate->p_hasSubLinks;
qry->hasAggs = pstate->p_hasAggs;
if (pstate->p_hasAggs || qry->groupClause || qry->havingQual)
if (pstate->p_hasAggs || qry->groupClause)
parseCheckAggregates(pstate, qry);
if (forUpdate != NIL)
@ -2536,9 +2536,9 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt)
expr = transformExpr(pstate, expr);
/* Cannot contain subselects or aggregates */
if (contain_subplans(expr))
if (pstate->p_hasSubLinks)
elog(ERROR, "Cannot use subselects in EXECUTE parameters");
if (contain_agg_clause(expr))
if (pstate->p_hasAggs)
elog(ERROR, "Cannot use aggregates in EXECUTE parameters");
given_type_id = exprType(expr);