Re: Getting to grips with Recursive CTEs.

From: Pól Ua Laoínecháin <linehanp(at)tcd(dot)ie>
To: "Miguel Beltran R(dot)" <yourpadre(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Getting to grips with Recursive CTEs.
Date: 2019-10-08 05:52:33
Message-ID: CAF4RT5TxSd8wyEmYJkzuohcwGStvvyct=EKeOOsxc0_A6QaYvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hola Miquel,

y gracias por tu contribución,

> You are not using a recursive function because it is needed to call the table "rcte" in the UNION ALL
> But it will fail because t3.parent is null at the beginning, so try this another one

> WITH rcte (child, parent) AS
> (
> SELECT parent AS child, '' AS parent FROM tree t1
> WHERE Parent NOT IN (SELECT child FROM tree)
> UNION ALL
> SELECT t2.child, t3.parent FROM tree t2
> JOIN rcte t3 ON t2.parent >= t3.parent
> )

> I haven't tried.

That's great - I've played around with it a wee bit - still have a lot
to learn! :-)

Haven't had too much time - but I think it's slowly dawning on me.

Best regards,

Pól...

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Pól Ua Laoínecháin 2019-10-08 05:57:14 Re: Getting to grips with Recursive CTEs.
Previous Message Potvin 2019-09-26 16:37:07 RE: Security question