Re: How to generate the order if you know the next item for each item?

Поиск
Список
Период
Сортировка
От Rockdale Green
Тема Re: How to generate the order if you know the next item for each item?
Дата
Msg-id CAArxxWh0=hFNLGQ-BODXjqhFu2vJdg0+haKAEbqq6ph-H4A5Og@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How to generate the order if you know the next item for each item?  (Tony Shelver <tshelver@gmail.com>)
Список pgsql-sql
Thanks, I do not need functions at this time but will keep that in mind in the future. 

On Thu, Aug 5, 2021 at 10:33 AM Tony Shelver <tshelver@gmail.com> wrote:
We have some ordered processing that we need to do that can involve reading through 10s of thousands of records, with a lot of conditional processing.  We use functions almost exclusively for this, returning a table of results.


On Tue, 3 Aug 2021 at 18:22, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Tue, Aug 3, 2021 at 8:40 AM Rockdale Green <rockdale.green@gmail.com> wrote:
 can I do it in one query? 

Yes.
It might be just very simple and I have tried but somehow I am blocked. 


The feature you need is a recursive CTE (WITH RECURSIVE clause).  It requires an initial row (which in this case is task 3, the only task that doesn't appear as a task_order value) and a query to retrieve the next row(s) using the information available in the previous iteration.

The documentation and/or online resources can walk you through the specifics.

David J.

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

Предыдущее
От: Rockdale Green
Дата:
Сообщение: Re: How to generate the order if you know the next item for each item?
Следующее
От: "intmail01@gmail.com"
Дата:
Сообщение: Hide some tables