From: Paul Jungwirth <pj@illuminatedcomputing.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Is postorder tree traversal possible with recursive CTE's?
Date: Tue, 19 Jun 2018 14:31:50 -0700
Message-ID: <1e2e2542-3fbf-e419-fd9a-4e3f02421bbb@illuminatedcomputing.com> (raw)
In-Reply-To: <8C64B1D2-B326-44F3-8526-08B0AEEA29E4@gmail.com>
References: <5196CEBE-CF2E-48AF-A496-3CE2FE1B6FD2@gmail.com>
<CAN3Qy4rPoEOAGWJjwSEgAzE=oLwxHzGuSqVrSD-Dz8Wp+jn-2Q@mail.gmail.com>
<CAN3Qy4pBy+A-+BCkjEC==Y0M1Rgr1MXOqtHwX68PFQjhqumZLQ@mail.gmail.com>
<8C64B1D2-B326-44F3-8526-08B0AEEA29E4@gmail.com>
On 06/19/2018 02:05 PM, Alban Hertroys wrote:
> On the more theoretical front: The question remains whether it is possible to calculate fields in post-order tree traversal. I think that would be a semantically proper way to express this type of problem and it wouldn't need the kinds of pre/post-processing that after-the-fact aggregation (like in above solution) requires. So, leaner, and probably faster.
> That implies that the SQL committee thought of the possibility in the first place though, which I'm beginning to doubt...
If this interests you, you might enjoy this StackOverflow question:
https://stackoverflow.com/questions/35956486/generate-nested-json-with-couting-in-postgresql
Briefly, how do you construct a nested JSON structure from a recursive
CTE? The only answers at that link rely on plpgsql, but of course that
is cheating. :-) I took a stab at it a couple years ago but couldn't
figure it out, and it seemed like post-order processing was exactly the
missing piece.
If anyone has any ideas I'd be intrigued to hear them!
--
Paul ~{:-)
pj@illuminatedcomputing.com
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: pj@illuminatedcomputing.com
Subject: Re: Is postorder tree traversal possible with recursive CTE's?
In-Reply-To: <1e2e2542-3fbf-e419-fd9a-4e3f02421bbb@illuminatedcomputing.com>
References: <5196CEBE-CF2E-48AF-A496-3CE2FE1B6FD2@gmail.com> <CAN3Qy4rPoEOAGWJjwSEgAzE=oLwxHzGuSqVrSD-Dz8Wp+jn-2Q@mail.gmail.com> <CAN3Qy4pBy+A-+BCkjEC==Y0M1Rgr1MXOqtHwX68PFQjhqumZLQ@mail.gmail.com> <8C64B1D2-B326-44F3-8526-08B0AEEA29E4@gmail.com> <1e2e2542-3fbf-e419-fd9a-4e3f02421bbb@illuminatedcomputing.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