Re: Getting to grips with Recursive CTEs.
Pól Ua Laoínecháin <[email protected]> Tue, 8 Oct 2019 06:52:33 +0100
| Newsgroups | gmane.comp.db.postgresql.novice |
|---|---|
| Message-ID | <CAF4RT5TxSd8wyEmYJkzuohcwGStvvyct=EKeOOsxc0_A6QaYvQ@mail.gmail.com> |
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...