Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit096e708

Browse files
committed
Fix failure to detect some cases of improperly-nested aggregates.
check_agg_arguments_walker() supposed that it needn't descend intothe arguments of a lower-level aggregate function, but this isjust wrong in the presence of multiple levels of sub-select. Theoversight would lead to executor failures on queries that shouldbe rejected. (Prior to v11, they actually were rejected, thanksto a "redundant" execution-time check.)Per bug #17835 from Anban Company. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/17835-4f29f3098b2d0ba4@postgresql.org
1 parent7e31923 commit096e708

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

‎src/backend/parser/parse_agg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,7 @@ check_agg_arguments_walker(Node *node,
728728
context->min_agglevel>agglevelsup)
729729
context->min_agglevel=agglevelsup;
730730
}
731-
/* no need to examine args of the inner aggregate */
732-
return false;
731+
/* Continue and descend into subtree */
733732
}
734733
if (IsA(node,GroupingFunc))
735734
{

‎src/test/regress/expected/aggregates.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,12 @@ select (select max(min(unique1)) from int8_tbl) from tenk1;
12481248
ERROR: aggregate function calls cannot be nested
12491249
LINE 1: select (select max(min(unique1)) from int8_tbl) from tenk1;
12501250
^
1251+
select avg((select avg(a1.col1 order by (select avg(a2.col2) from tenk1 a3))
1252+
from tenk1 a1(col1)))
1253+
from tenk1 a2(col2);
1254+
ERROR: aggregate function calls cannot be nested
1255+
LINE 1: select avg((select avg(a1.col1 order by (select avg(a2.col2)...
1256+
^
12511257
--
12521258
-- Test removal of redundant GROUP BY columns
12531259
--

‎src/test/regress/sql/aggregates.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ drop table minmaxtest cascade;
419419
-- check for correct detection of nested-aggregate errors
420420
selectmax(min(unique1))from tenk1;
421421
select (selectmax(min(unique1))from int8_tbl)from tenk1;
422+
selectavg((selectavg(a1.col1order by (selectavg(a2.col2)from tenk1 a3))
423+
from tenk1 a1(col1)))
424+
from tenk1 a2(col2);
422425

423426
--
424427
-- Test removal of redundant GROUP BY columns

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp