]> granicus.if.org Git - postgresql/commitdiff
Re-allow SRFs and window functions within sub-selects within aggregates.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Jun 2017 21:51:11 +0000 (17:51 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Jun 2017 21:51:11 +0000 (17:51 -0400)
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 commit
0436f6bde by copying the logic for window functions ... but that was
broken too, and had been since commit eaccfded9.

Repair both cases in HEAD, and the window function case back to 9.3.
9.2 gets this right.

src/backend/parser/parse_agg.c

index c984b7d5e469fbc13ae246682d9ce76140d82d3c..048b3c124882e87c297553383467ca1fb68849fb 100644 (file)
@@ -508,7 +508,7 @@ check_agg_arguments_walker(Node *node,
                return false;
        }
        /* We can throw error on sight for a window function */
-       if (IsA(node, WindowFunc))
+       if (IsA(node, WindowFunc) && context->sublevels_up == 0)
                ereport(ERROR,
                                (errcode(ERRCODE_GROUPING_ERROR),
                                 errmsg("aggregate function calls cannot contain window function calls"),