1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# name: test/sql/binder/alias_qualification_group_by.test
# description: Test alias.name resolution in GROUP BY clause
# group: [binder]
# grouping by a projection alias
query II
SELECT a % 2 AS x, COUNT(*) AS cnt
FROM (VALUES (1),(2),(3),(4)) t(a)
GROUP BY alias.x
ORDER BY x;
----
0 2
1 2
# quoted alias in GROUP BY
query II
SELECT (a/2)::INT AS "Half", COUNT(*) AS c
FROM (VALUES (1),(2),(3),(4)) t(a)
GROUP BY alias."Half"
ORDER BY "Half";
----
0 1
1 1
2 2
# Table actually named `alias` should keep working and be prioritized over alias references
statement ok
CREATE TABLE alias (g INT);
statement ok
INSERT INTO alias VALUES (1), (1), (2);
query II
SELECT g AS x, COUNT(*) c FROM alias
GROUP BY alias.g
ORDER BY x;
----
1 2
2 1
# GROUP BY on values that are a part of an expression
statement error
SELECT a + 1 AS x, alias.x % 2 AS y, SUM(a) AS s
FROM (VALUES (1),(2),(3)) t(a)
GROUP BY alias.y
ORDER BY y;
----
Binder Error
# GROUP BY for inside-expression alias calling from the GROUP BY clause
statement error
SELECT a as x FROM (VALUES (1),(2),(3)) t(a)
GROUP BY alias.x + 1
ORDER BY alias.x;
----
Binder Error
|