Recursion in plpgsql - Mailing list pgsql-general

From Uros Gruber
Subject Recursion in plpgsql
Date
Msg-id 93652058190.20020330233715@sir-mag.com
Whole thread Raw
List pgsql-general
Hi!

i have one table with categories. And columns important for
this to work. ID_CATEGORY and ID_PARENT. Now i want to do
"HERE-YOU-ARE" navigation. First here is my PHP code for
this.

function catPath( $cat, $file ) {
    static $p;
    $path = $p;

    $strSQL = "SELECT Name,Parent FROM category WHERE IDCategory='$cat'";
    $objDB->query( $strSQL );
    $objDB->next_record();
    $parent = $objDB->f( "Parent" );
    $name = $objDB->f( "Name" );

    $intProdCount = countProd( $cat );

    if ( strlen( $parent ) > 0 ) {
       if ( $intProdCount > 0 ) {
          $p = "<a href=\"$file?cat=$cat\">$name</a>";
       } else {
          $p = $name;
       }
       $p .= "<img width=\"10\" height=\"10\" src=\"img/design/rarr.gif\"> $path";
       catPath( $parent, $file );
    }

    return $p;
}
This code is OK, but if i'm deeper in the tree code is
slower and there is more sql queries. So i wan't to do this
on sql server with plpgsql.

I have 2 questions:

How can i tell function to call herself like up in PHP
example. And then is it possible to put data in some kind
temporary table and when it finish doing recursion i will get
data from that table and then use it in PHP.

Is there anyone who can know how to solve this or maybe have
better idea or maybe it not worth to worry about this because
it's fast enough.

--
bye
 Uros                          mailto:uros@sir-mag.com


pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Where doc mailing list
Next
From: Vince Vielhaber
Date:
Subject: Re: Where doc mailing list