Re: WITH RECURSIVE doesn't work properly for me

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: WITH RECURSIVE doesn't work properly for me
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B17C57008@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: WITH RECURSIVE doesn't work properly for me  (Jing Fan <fanjing09@gmail.com>)
Ответы Re: WITH RECURSIVE doesn't work properly for me
Список pgsql-general
Jing Fan wrote:
> I am sorry but I still don't understand why it doesn't work. Possibly I misunderstand how with
> recursive works?
> In my opinion,
> with recursive table as{
>     seed statement
>     union
>     recursive statement
> }
> In every iteration, It will just generate results from seed statement union recursive statement and
> put them into a new temporary table, and then compare the results with the former temporary table and
> check if there are any new tuples. If no new tuples, just stop iteration. Is there any tricky things
> about recursive statement?

That is correct.

Let's assume that we have three nodes A, B and C.
Also, A points to B, B points to C and C points to B.

Let's assume that we already generated (A, B, 1) and (A, C, 2)
in previous iterations.

Then the "recursive statement" will generate the new
rows (A, C, 2) and (A, B, 3).
The SELECT ... GROUP BY only surrounds the recursive statement,
So the result will still be (A, C, 2) and (A, B, 3).

Then the UNION will take care of the first triple, but the second
one will be added in this iteration.

And so on ad infinitum.

Yours,
Laurenz Albe

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

Предыдущее
От: Jing Fan
Дата:
Сообщение: Re: WITH RECURSIVE doesn't work properly for me
Следующее
От: Jing Fan
Дата:
Сообщение: Re: WITH RECURSIVE doesn't work properly for me