From: | Rockdale Green <rockdale(dot)green(at)gmail(dot)com> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to generate the order if you know the next item for each item? |
Date: | 2021-08-05 16:53:25 |
Message-ID: | CAArxxWgo+bKGrvtajmrcfwxiqM+4iUsfbXhVs0=MnmjtNVOXhw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Thanks David. With RECURSIVE I got what I needed.
On Tue, Aug 3, 2021 at 12:22 PM David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
> On Tue, Aug 3, 2021 at 8:40 AM Rockdale Green <rockdale(dot)green(at)gmail(dot)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.
>
From | Date | Subject | |
---|---|---|---|
Next Message | Rockdale Green | 2021-08-05 16:55:32 | Re: How to generate the order if you know the next item for each item? |
Previous Message | David G. Johnston | 2021-08-05 14:38:46 | Re: Show table and columns with null value and count |