Skip to content

Commit 823e739

Browse files
committed
Test GROUP BY matching of join columns that are type-coerced by USING.
If we have, say, an int column that is left-joined to a bigint column with USING, the merged column is the int column promoted to bigint. GROUP BY's tests for whether grouping on the merged column allows a reference to the underlying column, or vice versa, should know about that relationship --- and they do. But I nearly broke this case with an ill-advised optimization, so the lack of any test coverage for it seems like a bad idea.
1 parent c5f3b53 commit 823e739

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/test/regress/expected/aggregates.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,32 @@ drop table t2;
11941194
drop table t3;
11951195
drop table p_t1;
11961196
--
1197+
-- Test GROUP BY matching of join columns that are type-coerced due to USING
1198+
--
1199+
create temp table t1(f1 int, f2 bigint);
1200+
create temp table t2(f1 bigint, f22 bigint);
1201+
select f1 from t1 left join t2 using (f1) group by f1;
1202+
f1
1203+
----
1204+
(0 rows)
1205+
1206+
select f1 from t1 left join t2 using (f1) group by t1.f1;
1207+
f1
1208+
----
1209+
(0 rows)
1210+
1211+
select t1.f1 from t1 left join t2 using (f1) group by t1.f1;
1212+
f1
1213+
----
1214+
(0 rows)
1215+
1216+
-- only this one should fail:
1217+
select t1.f1 from t1 left join t2 using (f1) group by f1;
1218+
ERROR: column "t1.f1" must appear in the GROUP BY clause or be used in an aggregate function
1219+
LINE 1: select t1.f1 from t1 left join t2 using (f1) group by f1;
1220+
^
1221+
drop table t1, t2;
1222+
--
11971223
-- Test combinations of DISTINCT and/or ORDER BY
11981224
--
11991225
select array_agg(a order by b)

src/test/regress/sql/aggregates.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,21 @@ drop table t2;
432432
drop table t3;
433433
drop table p_t1;
434434

435+
--
436+
-- Test GROUP BY matching of join columns that are type-coerced due to USING
437+
--
438+
439+
create temp table t1(f1 int, f2 bigint);
440+
create temp table t2(f1 bigint, f22 bigint);
441+
442+
select f1 from t1 left join t2 using (f1) group by f1;
443+
select f1 from t1 left join t2 using (f1) group by t1.f1;
444+
select t1.f1 from t1 left join t2 using (f1) group by t1.f1;
445+
-- only this one should fail:
446+
select t1.f1 from t1 left join t2 using (f1) group by f1;
447+
448+
drop table t1, t2;
449+
435450
--
436451
-- Test combinations of DISTINCT and/or ORDER BY
437452
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy