Re: stumped on a with recursive example

Поиск
Список
Период
Сортировка
От Henry Drexler
Тема Re: stumped on a with recursive example
Дата
Msg-id CAAtgU9R9BBjeELLH+K0gYSb6ySd+0cvphqonrTsJE4+Qm9Zwpw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: stumped on a with recursive example  (Johan Nel <johan.nel@xsinet.co.za>)
Список pgsql-novice

I would use the following query:
WITH RECURSIVE search_graph AS (
 SELECT id, parent_department, "name", "name"::text as path, 0 AS depth
   FROM department d
   WHERE d.parent_department IS NULL
 UNION ALL
 SELECT r.id, r.parent_department, r."name", sg.path||'/'||r.id as path,
        sg.depth + 1 AS depth
   FROM department r, search_graph sg
   WHERE r.parent_department = sg.id
)
SELECT * FROM search_graph ORDER BY path;

Hopefully that will give you a better understanding of the structure of the return.

Johan Nel
Pretoria, South Africa.


Thank you for the reply, that looks like it will help. 

В списке pgsql-novice по дате отправления:

Предыдущее
От: Johan Nel
Дата:
Сообщение: Re: stumped on a with recursive example
Следующее
От: "Ioannis Anagnostopoulos"
Дата:
Сообщение: Linux server connection process consumes all memory