Re: Recursive Parent-Child Function Bottom Up - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Recursive Parent-Child Function Bottom Up
Date
Msg-id 4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com
Whole thread Raw
In response to Re: Recursive Parent-Child Function Bottom Up  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: Recursive Parent-Child Function Bottom Up  (Rob Sargent <robjsargent@gmail.com>)
Re: Recursive Parent-Child Function Bottom Up  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-general
> On 26 Jul 2021, at 17:52, Alban Hertroys <haramrae@gmail.com> wrote:
> Something like this:
>
> with recursive foo (id, parent, children_ids) as (
>     select id, parent, null::text
>       from tree t
>      where not exists (
>         select 1 from tree c where c.parent = t.id
>      )
>     union all
>     select t.id, t.parent
>     ,    f.id || case f.children_ids when '' then '' else ',’ end || f.children_ids
>       from foo f
>       join tree t on f.parent = t.id
>      where f.parent <> 0
> ;

Almost, the null::text in the initial select should of course be '’ in your case, and a unicode quote slipped into the
laststring of that case statement. 

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.




pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: Recursive Parent-Child Function Bottom Up
Next
From: Rob Sargent
Date:
Subject: Re: Recursive Parent-Child Function Bottom Up