diff options
| author | Tom Lane | 2003-06-06 15:04:03 +0000 |
|---|---|---|
| committer | Tom Lane | 2003-06-06 15:04:03 +0000 |
| commit | e649796f128bd8702ba5744d36f4e8cb81f0b754 (patch) | |
| tree | 050eda51ad8f0298731316ccf61db2c01a2863a3 /src/test | |
| parent | 2c93861f7cef99b4613abd37ed7e4c15a95754b4 (diff) | |
Implement outer-level aggregates to conform to the SQL spec, with
extensions to support our historical behavior. An aggregate belongs
to the closest query level of any of the variables in its argument,
or the current query level if there are no variables (e.g., COUNT(*)).
The implementation involves adding an agglevelsup field to Aggref,
and treating outer aggregates like outer variables at planning time.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/aggregates.out | 20 | ||||
| -rw-r--r-- | src/test/regress/sql/aggregates.sql | 13 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/test/regress/expected/aggregates.out b/src/test/regress/expected/aggregates.out index 9378ce7c9bc..a0009eed690 100644 --- a/src/test/regress/expected/aggregates.out +++ b/src/test/regress/expected/aggregates.out @@ -137,3 +137,23 @@ SELECT newcnt(four) AS cnt_1000 FROM onek; 1000 (1 row) +-- test for outer-level aggregates +-- this should work +select ten, sum(distinct four) from onek a +group by ten +having exists (select 1 from onek b where sum(distinct a.four) = b.four); + ten | sum +-----+----- + 0 | 2 + 2 | 2 + 4 | 2 + 6 | 2 + 8 | 2 +(5 rows) + +-- this should fail because subquery has an agg of its own in WHERE +select ten, sum(distinct four) from onek a +group by ten +having exists (select 1 from onek b + where sum(distinct a.four + b.four) = b.four); +ERROR: Aggregates not allowed in WHERE clause diff --git a/src/test/regress/sql/aggregates.sql b/src/test/regress/sql/aggregates.sql index 00cc6daf9f5..38335bcf083 100644 --- a/src/test/regress/sql/aggregates.sql +++ b/src/test/regress/sql/aggregates.sql @@ -49,3 +49,16 @@ SELECT newsum(four) AS sum_1500 FROM onek; SELECT newcnt(four) AS cnt_1000 FROM onek; + +-- test for outer-level aggregates + +-- this should work +select ten, sum(distinct four) from onek a +group by ten +having exists (select 1 from onek b where sum(distinct a.four) = b.four); + +-- this should fail because subquery has an agg of its own in WHERE +select ten, sum(distinct four) from onek a +group by ten +having exists (select 1 from onek b + where sum(distinct a.four + b.four) = b.four); |
