Fix failure to detect some cases of improperly-nested aggregates.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Mar 2023 16:40:28 +0000 (12:40 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Mar 2023 16:40:28 +0000 (12:40 -0400)
commit0736b11318daaa38f808197f707fabed79b3aef8
treeb2e930c58580d8b84690875c5929aef36717dcef
parentb18327489b3be5c30ae51eaf24479da7c0af1aaa
Fix failure to detect some cases of improperly-nested aggregates.

check_agg_arguments_walker() supposed that it needn't descend into
the arguments of a lower-level aggregate function, but this is
just wrong in the presence of multiple levels of sub-select.  The
oversight would lead to executor failures on queries that should
be rejected.  (Prior to v11, they actually were rejected, thanks
to a "redundant" execution-time check.)

Per bug #17835 from Anban Company.  Back-patch to all supported
branches.

Discussion: http://postgr.es/m/17835-4f29f3098b2d0ba4@postgresql.org
src/backend/parser/parse_agg.c
src/test/regress/expected/aggregates.out
src/test/regress/sql/aggregates.sql