!3326 【bugfixed】解决orderby 列的别名在distinct中也报错的问题
Merge pull request !3326 from laishenghao/distinct-alias
This commit is contained in:
@ -2426,7 +2426,9 @@ static void CheckOrderbyColumns(ParseState* pstate, List* targetList, bool isAgg
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!isFound) {
|
||||
Node* refExpr = transformExpr(pstate, (Node*)colRef, EXPR_KIND_ORDER_BY);
|
||||
ListCell* tcell = nullptr;
|
||||
foreach(tcell, targetList) {
|
||||
|
||||
@ -1093,5 +1093,39 @@ LINE 1: ...elect a, min(b), group_concat(distinct c order by d) as orde...
|
||||
^
|
||||
CONTEXT: referenced column: order_not_in_distinct
|
||||
reset group_concat_max_len;
|
||||
-- 12. test alias default
|
||||
create table dob_alias_only(
|
||||
c1 int,
|
||||
c2 int
|
||||
);
|
||||
insert into dob_alias_only values(1, 2);
|
||||
insert into dob_alias_only values(2, 1);
|
||||
insert into dob_alias_only values(2, 1);
|
||||
reset behavior_compat_options;
|
||||
select distinct c1 as a1 from dob_alias_only order by c1;
|
||||
a1
|
||||
----
|
||||
1
|
||||
2
|
||||
(2 rows)
|
||||
|
||||
select distinct c1 as c2, c2 as c1 from dob_alias_only order by c1;
|
||||
c2 | c1
|
||||
----+----
|
||||
2 | 1
|
||||
1 | 2
|
||||
(2 rows)
|
||||
|
||||
select distinct c1 as c2, c2 as c1 from dob_alias_only order by c2;
|
||||
c2 | c1
|
||||
----+----
|
||||
1 | 2
|
||||
2 | 1
|
||||
(2 rows)
|
||||
|
||||
select distinct c1 + 1 as a1, c2 + 2 as a2 from dob_alias_only order by c1; -- should error
|
||||
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
|
||||
LINE 1: ... c1 + 1 as a1, c2 + 2 as a2 from dob_alias_only order by c1;
|
||||
^
|
||||
\c postgres
|
||||
drop database dob_bdb;
|
||||
|
||||
@ -303,5 +303,20 @@ reset behavior_compat_options;
|
||||
select a, min(b), group_concat(distinct c order by d) as order_not_in_distinct from dob_func_t group by a order by a;
|
||||
reset group_concat_max_len;
|
||||
|
||||
-- 12. test alias default
|
||||
create table dob_alias_only(
|
||||
c1 int,
|
||||
c2 int
|
||||
);
|
||||
insert into dob_alias_only values(1, 2);
|
||||
insert into dob_alias_only values(2, 1);
|
||||
insert into dob_alias_only values(2, 1);
|
||||
|
||||
reset behavior_compat_options;
|
||||
select distinct c1 as a1 from dob_alias_only order by c1;
|
||||
select distinct c1 as c2, c2 as c1 from dob_alias_only order by c1;
|
||||
select distinct c1 as c2, c2 as c1 from dob_alias_only order by c2;
|
||||
select distinct c1 + 1 as a1, c2 + 2 as a2 from dob_alias_only order by c1; -- should error
|
||||
|
||||
\c postgres
|
||||
drop database dob_bdb;
|
||||
|
||||
Reference in New Issue
Block a user