diff options
| author | Tom Lane | 2000-02-19 23:45:07 +0000 |
|---|---|---|
| committer | Tom Lane | 2000-02-19 23:45:07 +0000 |
| commit | 751a14e60c309068557e68c8f322007e0522947a (patch) | |
| tree | 327a52ee6b11fd95134d70b329fe567a196843f6 /src/test | |
| parent | b48f983ec34683c5ce2a859e6eddfb1724885af7 (diff) | |
Repair longstanding violation of SQL92 semantics: GROUP BY would
interpret a column name as an output column alias (targetlist AS name),
ather than a real column name as it ought to. According to the spec,
only ORDER BY should look at output column names. I left in GROUP BY's
willingness to use an output column number ('GROUP BY 2'), even though
this is also contrary to the spec --- again, only ORDER BY is supposed
to accept that. But there is no possible reason to want to GROUP BY
an integer constant, so keeping this old behavior won't break any
SQL-compliant queries. DISTINCT ON will behave the same as GROUP BY.
Change numerology regress test, which depended on the incorrect
behavior.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/numerology.out | 28 | ||||
| -rw-r--r-- | src/test/regress/sql/numerology.sql | 13 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/test/regress/expected/numerology.out b/src/test/regress/expected/numerology.out index 131e5f7e64b..8e13a9e6acb 100644 --- a/src/test/regress/expected/numerology.out +++ b/src/test/regress/expected/numerology.out @@ -88,7 +88,7 @@ SELECT DISTINCT f1 AS two FROM TEMP_GROUP; SELECT f1 AS two, max(f3) AS max_float, min(f3) as min_float FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, max_float, min_float; two | max_float | min_float -----+----------------------+----------------------- @@ -96,19 +96,17 @@ SELECT f1 AS two, max(f3) AS max_float, min(f3) as min_float 2 | 0 | -1.2345678901234e+200 (2 rows) +-- Postgres used to accept this, but it is clearly against SQL92 to +-- interpret GROUP BY arguments as result column names; they should +-- be source column names *only*. An error is expected. SELECT f1 AS two, max(f3) AS max_float, min(f3) AS min_float FROM TEMP_GROUP GROUP BY two ORDER BY two, max_float, min_float; - two | max_float | min_float ------+----------------------+----------------------- - 1 | 1.2345678901234e+200 | 0 - 2 | 0 | -1.2345678901234e+200 -(2 rows) - +ERROR: Attribute 'two' not found SELECT f1 AS two, (max(f3) + 1) AS max_plus_1, (min(f3) - 1) AS min_minus_1 FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, min_minus_1; two | max_plus_1 | min_minus_1 -----+----------------------+----------------------- @@ -116,14 +114,16 @@ SELECT f1 AS two, (max(f3) + 1) AS max_plus_1, (min(f3) - 1) AS min_minus_1 2 | 1 | -1.2345678901234e+200 (2 rows) -SELECT f1 AS two, (max(f3) + 1) AS max_plus_1, (min(f3) - 1) AS min_minus_1 +SELECT f1 AS two, + max(f2) + min(f2) AS max_plus_min, + min(f3) - 1 AS min_minus_1 FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, min_minus_1; - two | max_plus_1 | min_minus_1 ------+----------------------+----------------------- - 1 | 1.2345678901234e+200 | -1 - 2 | 1 | -1.2345678901234e+200 + two | max_plus_min | min_minus_1 +-----+--------------+----------------------- + 1 | 0 | -1 + 2 | 0 | -1.2345678901234e+200 (2 rows) DROP TABLE TEMP_INT2; diff --git a/src/test/regress/sql/numerology.sql b/src/test/regress/sql/numerology.sql index 35975f3bd61..b30f008bffb 100644 --- a/src/test/regress/sql/numerology.sql +++ b/src/test/regress/sql/numerology.sql @@ -67,9 +67,12 @@ SELECT DISTINCT f1 AS two FROM TEMP_GROUP; SELECT f1 AS two, max(f3) AS max_float, min(f3) as min_float FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, max_float, min_float; +-- Postgres used to accept this, but it is clearly against SQL92 to +-- interpret GROUP BY arguments as result column names; they should +-- be source column names *only*. An error is expected. SELECT f1 AS two, max(f3) AS max_float, min(f3) AS min_float FROM TEMP_GROUP GROUP BY two @@ -77,12 +80,14 @@ SELECT f1 AS two, max(f3) AS max_float, min(f3) AS min_float SELECT f1 AS two, (max(f3) + 1) AS max_plus_1, (min(f3) - 1) AS min_minus_1 FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, min_minus_1; -SELECT f1 AS two, (max(f3) + 1) AS max_plus_1, (min(f3) - 1) AS min_minus_1 +SELECT f1 AS two, + max(f2) + min(f2) AS max_plus_min, + min(f3) - 1 AS min_minus_1 FROM TEMP_GROUP - GROUP BY two + GROUP BY f1 ORDER BY two, min_minus_1; DROP TABLE TEMP_INT2; |
