support order siblings by in cte base table
This commit is contained in:
@ -21307,6 +21307,41 @@ select_no_parens:
|
||||
yyscanner);
|
||||
$$ = $2;
|
||||
}
|
||||
| with_clause select_clause siblings_clause
|
||||
{
|
||||
SelectStmt* stmt = (SelectStmt *) $2;
|
||||
insertSelectOptions((SelectStmt *) $2, NIL, NIL,
|
||||
NULL, NULL, $1,
|
||||
yyscanner);
|
||||
StartWithClause* swc = (StartWithClause*) stmt->startWithClause;
|
||||
if (swc == NULL) {
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("order siblings by clause can only be used on start-with qualifed relations"),
|
||||
parser_errposition(@2)));
|
||||
} else {
|
||||
swc->siblingsOrderBy = $3;
|
||||
}
|
||||
$$ = $2;
|
||||
}
|
||||
|
||||
| with_clause select_clause siblings_clause sort_clause
|
||||
{
|
||||
SelectStmt* stmt = (SelectStmt *) $2;
|
||||
insertSelectOptions((SelectStmt *) $2, $4, NIL,
|
||||
NULL, NULL, $1,
|
||||
yyscanner);
|
||||
StartWithClause* swc = (StartWithClause*) stmt->startWithClause;
|
||||
if (swc == NULL) {
|
||||
ereport(errstate,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("order siblings by clause can only be used on start-with qualifed relations"),
|
||||
parser_errposition(@2)));
|
||||
} else {
|
||||
swc->siblingsOrderBy = $3;
|
||||
}
|
||||
$$ = $2;
|
||||
}
|
||||
| with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit opt_into_clause
|
||||
{
|
||||
FilterStartWithUseCases((SelectStmt *) $2, $4, yyscanner, @4);
|
||||
|
@ -580,6 +580,14 @@ select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1
|
||||
1 | | 1 | 0
|
||||
(3 rows)
|
||||
|
||||
with cte1 as (select * from t1) select *, connect_by_iscycle from cte1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls last;
|
||||
c1 | c2 | c3 | connect_by_iscycle
|
||||
----+----+----+--------------------
|
||||
1 | 1 | 1 | 0
|
||||
1 | 1 | 1 | 0
|
||||
1 | | 1 | 0
|
||||
(3 rows)
|
||||
|
||||
delete from t1 where c2 is null;
|
||||
select *, connect_by_iscycle from t1 start with c1<3 connect by nocycle prior c1<c2 order siblings by NLSSORT (c1, ' NLS_SORT = generic_m_ci ');
|
||||
c1 | c2 | c3 | connect_by_iscycle
|
||||
|
@ -228,6 +228,7 @@ select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1
|
||||
insert into t1 values(1,NULL,1);
|
||||
select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls first;
|
||||
select *, connect_by_iscycle from t1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls last;
|
||||
with cte1 as (select * from t1) select *, connect_by_iscycle from cte1 start with c1=1 connect by nocycle prior c1=c2 order siblings by 1,2 nulls last;
|
||||
delete from t1 where c2 is null;
|
||||
|
||||
select *, connect_by_iscycle from t1 start with c1<3 connect by nocycle prior c1<c2 order siblings by NLSSORT (c1, ' NLS_SORT = generic_m_ci ');
|
||||
|
Reference in New Issue
Block a user