mirror of
https://github.com/postgres/postgres.git
synced 2025-08-25 20:23:07 +03:00
Re-allow SRFs and window functions within sub-selects within aggregates.
check_agg_arguments_walker threw an error upon seeing a SRF or window function, but that is too aggressive: if the function is within a sub-select then it's perfectly fine. I broke the SRF case in commit0436f6bde
by copying the logic for window functions ... but that was broken too, and had been since commiteaccfded9
. Repair both cases in HEAD, and the window function case back to 9.3. 9.2 gets this right.
This commit is contained in:
@@ -705,21 +705,28 @@ check_agg_arguments_walker(Node *node,
|
||||
}
|
||||
/* Continue and descend into subtree */
|
||||
}
|
||||
/* We can throw error on sight for a set-returning function */
|
||||
if ((IsA(node, FuncExpr) &&((FuncExpr *) node)->funcretset) ||
|
||||
(IsA(node, OpExpr) &&((OpExpr *) node)->opretset))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("aggregate function calls cannot contain set-returning function calls"),
|
||||
errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
|
||||
parser_errposition(context->pstate, exprLocation(node))));
|
||||
/* We can throw error on sight for a window function */
|
||||
if (IsA(node, WindowFunc))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregate function calls cannot contain window function calls"),
|
||||
parser_errposition(context->pstate,
|
||||
((WindowFunc *) node)->location)));
|
||||
|
||||
/*
|
||||
* SRFs and window functions can be rejected immediately, unless we are
|
||||
* within a sub-select within the aggregate's arguments; in that case
|
||||
* they're OK.
|
||||
*/
|
||||
if (context->sublevels_up == 0)
|
||||
{
|
||||
if ((IsA(node, FuncExpr) &&((FuncExpr *) node)->funcretset) ||
|
||||
(IsA(node, OpExpr) &&((OpExpr *) node)->opretset))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("aggregate function calls cannot contain set-returning function calls"),
|
||||
errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
|
||||
parser_errposition(context->pstate, exprLocation(node))));
|
||||
if (IsA(node, WindowFunc))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_GROUPING_ERROR),
|
||||
errmsg("aggregate function calls cannot contain window function calls"),
|
||||
parser_errposition(context->pstate,
|
||||
((WindowFunc *) node)->location)));
|
||||
}
|
||||
if (IsA(node, Query))
|
||||
{
|
||||
/* Recurse into subselects */
|
||||
|
Reference in New Issue
Block a user