Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Chicago, IL

    Unanswered: Recursive SQL (Traversing Trees)

    Hi, I'm actually new to this forum, and I decided to post here after seeing something in the archives regarding recursive SQL, but the function was in PL/PgSQL, and was just has taxing query-wise as doing it from C or even Perl.

    I'm working with a bit of a 'trouble' dataset, in that:

    Parent | Child
    "AAA" | "BBB"
    "AAA" | "CCC"
    "BBB" | "AAA"
    "BBB" | "DDD"
    "CCC" | "BBB"
    "DDD" | "EEE"
    "DDD" | "FFF"
    "EEE" | "DDD"
    "FFF" | "EEE"

    Now, i need to grab an arbitrary level of the root parent's children, meaning:

    If I wanted to go two levels, I would need to find the Children of "AAA" and the children of all of "AAA"s children, whereas one level down would just be "AAA"s children.

    Any thoughts on how I could do this without looping through each result in PL/PgSQL, and calling the function again for each result? (in reference to <a href="" this thread</a>)

  2. #2
    Join Date
    Jan 2004

    Re: Recursive SQL (Traversing Trees)

    May be with subselects but the problem is that you will need one subselect per level. This is not a good solution.
    Other way may be using a cursor, so you won't need a recursive function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts