Доброго времени суток!
Решил пощупать CTE
2.1.0.17735 RC
3-й диалект
create table test_table1
(id integer not null,
master_id integer);
commit;
insert into test_table1 values (1,null);
insert into test_table1 values (2,1);
insert into test_table1 values (3,2);
insert into test_table1 values (4,null);
insert into test_table1 values (5,4);
insert into test_table1 values (6,1);
commit;
Пример 1
with recursive r_tree
(ID, LEV, PATH) as
(
select id,0 from test_table1 t
where master_id is null
union all
select t.id,r.lev +1,
r.path || '.' || cast(t.id as varchar(8))
from test_table1 t1 inner join r_tree r
on t1.master_id = r.id
)
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Unexpected end of command - line 13, column 38.
Опять неверный column - правда, это мелочь.
Пример 2
with recursive r_tree
(ID, LEV,path,tst) as
(
select id,0,cast(id as varchar(8)),Null from test_table1 t
where master_id is null
union all
select t1.id,r.lev +1,
r.path || '.' || cast(t1.id as varchar(8)),
(select sum(id) from test_table1)
from test_table1 t1 inner join r_tree r
on t1.master_id = r.id
)
SELECT e.*, rr.LEV, rr.PATH,rr.tst
FROM Test_table1 e, R_TREE rr
WHERE e.ID = rr.ID
Overflow occurred during data type conversion.
conversion error from string 21.
хотя формально все верно (аналогичный пример с Count работает)
Пример 3
with recursive r_tree
(ID, LEV,path,tst) as
(
select first 1 id,0,cast(id as varchar(8)),1 from test_table1 t
where master_id is null
union all
select first 1 t2.id, r.lev +1,
r.path || '.' || cast(t2.id as varchar(8)),0
from r_tree r inner join test_table1 t2
on t2.master_id = r.id
order by t1.id desc
)
select * from r_tree
выполняется, но парсер игнорирует order by (алиас t1 нигде
не используется).
with recursive r_tree
(ID, LEV,path) as
(
select first 1 id,0,cast(id as varchar(8)) from test_table1 t
where master_id is null
union all
select first 1 t2.id, r.lev +1,
r.path || '.' || cast(t2.id as varchar(8))
from r_tree r inner join test_table1 t2
on t2.master_id = r.id
rows 1 to 2
)
select * from r_tree
rows здесь тоже игнорируется
Что-нибудь из этого является существенным?
С уважением, Евгений