aboutsummaryrefslogtreecommitdiff
path: root/src/test/regress/sql/groupingsets.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/regress/sql/groupingsets.sql')
-rw-r--r--src/test/regress/sql/groupingsets.sql51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/test/regress/sql/groupingsets.sql b/src/test/regress/sql/groupingsets.sql
index 90ba27257a9..add76ac4a3a 100644
--- a/src/test/regress/sql/groupingsets.sql
+++ b/src/test/regress/sql/groupingsets.sql
@@ -589,4 +589,55 @@ explain (costs off)
select (select grouping(v1)) from (values ((select 1))) v(v1) group by v1;
select (select grouping(v1)) from (values ((select 1))) v(v1) group by v1;
+-- test handling of subqueries in grouping sets
+create temp table gstest5(id integer primary key, v integer);
+insert into gstest5 select i, i from generate_series(1,5)i;
+
+explain (verbose, costs off)
+select grouping((select t1.v from gstest5 t2 where id = t1.id)),
+ (select t1.v from gstest5 t2 where id = t1.id) as s
+from gstest5 t1
+group by grouping sets(v, s)
+order by case when grouping((select t1.v from gstest5 t2 where id = t1.id)) = 0
+ then (select t1.v from gstest5 t2 where id = t1.id)
+ else null end
+ nulls first;
+
+select grouping((select t1.v from gstest5 t2 where id = t1.id)),
+ (select t1.v from gstest5 t2 where id = t1.id) as s
+from gstest5 t1
+group by grouping sets(v, s)
+order by case when grouping((select t1.v from gstest5 t2 where id = t1.id)) = 0
+ then (select t1.v from gstest5 t2 where id = t1.id)
+ else null end
+ nulls first;
+
+explain (verbose, costs off)
+select grouping((select t1.v from gstest5 t2 where id = t1.id)),
+ (select t1.v from gstest5 t2 where id = t1.id) as s,
+ case when grouping((select t1.v from gstest5 t2 where id = t1.id)) = 0
+ then (select t1.v from gstest5 t2 where id = t1.id)
+ else null end as o
+from gstest5 t1
+group by grouping sets(v, s)
+order by o nulls first;
+
+select grouping((select t1.v from gstest5 t2 where id = t1.id)),
+ (select t1.v from gstest5 t2 where id = t1.id) as s,
+ case when grouping((select t1.v from gstest5 t2 where id = t1.id)) = 0
+ then (select t1.v from gstest5 t2 where id = t1.id)
+ else null end as o
+from gstest5 t1
+group by grouping sets(v, s)
+order by o nulls first;
+
+-- test handling of expressions that should match lower target items
+explain (costs off)
+select a < b and b < 3 from (values (1, 2)) t(a, b) group by rollup(a < b and b < 3) having a < b and b < 3;
+select a < b and b < 3 from (values (1, 2)) t(a, b) group by rollup(a < b and b < 3) having a < b and b < 3;
+
+explain (costs off)
+select not a from (values(true)) t(a) group by rollup(not a) having not not a;
+select not a from (values(true)) t(a) group by rollup(not a) having not not a;
+
-- end