LINUX.ORG.RU

Взгляните на запрос

 , , рекурсивный запрос


1

1
with recursive temp1 (id, parent_id, value, type)
as (
    select
        t1.id,
        t1.parent_id,
        t1.value::text,
        t1.type
    from address as t1
    where t1.id = 10
    union
    select
        t2.id,
        t2.parent_id,
        t2.value || ', ' || temp1.value,
        t2.type
    from address as t2 inner join temp1 ON (temp1.parent_id = t2.id)
)
select
    value
from temp1
where type > 'locality'
order by type desc
limit 1;

Добрый день, подскажите, пожалуйста, как сделать так, что t1.id можно было задавать через where ко всему выражению? (или как бы так его превратить во view?)

★★

with recursive temp1 (id, parent_id, value, type, root_id)
as (
    select
        t1.id,
        t1.parent_id,
        t1.value::text,
        t1.type,
        t1.id as root_id
    from address as t1
--!!!    where t1.id = 3
    union all --!!! (сортировка не нужна)
    select
        t2.id,
        t2.parent_id,
        t2.value || ', ' || temp1.value,
        t2.type,
        temp1.root_id
    from address as t2 inner join temp1 ON (temp1.parent_id = t2.id)
)
select
    value
from temp1
where type > 'locality'
    and root_id = 3 --!!!
order by type desc
limit 1;
tnodir
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.