Skip site navigation (1) Skip section navigation (2)

Recursion in plpgsql

From: Uros Gruber <uros(at)sir-mag(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Recursion in plpgsql
Date: 2002-03-30 22:37:15
Message-ID: 93652058190.20020330233715@sir-mag.com (view raw or flat)
Thread:
Lists: 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(at)sir-mag(dot)com


Responses

pgsql-general by date

Next:From: Vince VielhaberDate: 2002-03-31 14:05:00
Subject: Re: Where doc mailing list
Previous:From: Bruce MomjianDate: 2002-03-30 20:35:42
Subject: Re: Where doc mailing list

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group