pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alban Hertroys <haramrae@gmail.com>
To: Avi Weinberg <AviW@gilat.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Recursive Parent-Child Function Bottom Up
Date: Mon, 26 Jul 2021 17:55:57 +0200
Message-ID: <4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com> (raw)
In-Reply-To: <903EB164-89AA-4CB4-A031-A707954E6B23@gmail.com>
References: <DB9PR07MB718032F033C6D95B92E5BAAECBE89@DB9PR07MB7180.eurprd07.prod.outlook.com>
	<903EB164-89AA-4CB4-A031-A707954E6B23@gmail.com>


> 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 last string 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.






view thread (7+ messages)  latest in thread

Message-ID: <4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com>
Permalink:  ../4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com/
Also on:    postgresql.org/message-id/4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: haramrae@gmail.com, AviW@gilat.com
  Subject: Re: Recursive Parent-Child Function Bottom Up
  In-Reply-To: <4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com>
  References: <DB9PR07MB718032F033C6D95B92E5BAAECBE89@DB9PR07MB7180.eurprd07.prod.outlook.com> <903EB164-89AA-4CB4-A031-A707954E6B23@gmail.com> <4FE3DD91-4494-4339-ABE2-21EA7C861059@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox