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

Commit5fd61bd

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 parentda6257e commit5fd61bd

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
@@ -735,8 +735,7 @@ check_agg_arguments_walker(Node *node,
735735
context->min_agglevel>agglevelsup)
736736
context->min_agglevel=agglevelsup;
737737
}
738-
/* no need to examine args of the inner aggregate */
739-
return false;
738+
/* Continue and descend into subtree */
740739
}
741740
if (IsA(node,GroupingFunc))
742741
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,12 @@ select (select max(min(unique1)) from int8_tbl) from tenk1;
12581258
ERROR: aggregate function calls cannot be nested
12591259
LINE 1: select (select max(min(unique1)) from int8_tbl) from tenk1;
12601260
^
1261+
select avg((select avg(a1.col1 order by (select avg(a2.col2) from tenk1 a3))
1262+
from tenk1 a1(col1)))
1263+
from tenk1 a2(col2);
1264+
ERROR: aggregate function calls cannot be nested
1265+
LINE 1: select avg((select avg(a1.col1 order by (select avg(a2.col2)...
1266+
^
12611267
--
12621268
-- Test removal of redundant GROUP BY columns
12631269
--

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ drop table minmaxtest cascade;
434434
-- check for correct detection of nested-aggregate errors
435435
selectmax(min(unique1))from tenk1;
436436
select (selectmax(min(unique1))from int8_tbl)from tenk1;
437+
selectavg((selectavg(a1.col1order by (selectavg(a2.col2)from tenk1 a3))
438+
from tenk1 a1(col1)))
439+
from tenk1 a2(col2);
437440

438441
--
439442
-- Test removal of redundant GROUP BY columns

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp