pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Uros Gruber <uros@sir-mag.com>
To: pgsql-general@postgresql.org
Subject: Recursion in plpgsql
Date: Sat, 30 Mar 2002 23:37:15 +0100
Message-ID: <93652058190.20020330233715@sir-mag.com> (raw)

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




view thread (8+ messages)  latest in thread

Message-ID: <93652058190.20020330233715@sir-mag.com>
Permalink:  ../93652058190.20020330233715@sir-mag.com/
Also on:    postgresql.org/message-id/93652058190.20020330233715@sir-mag.com

 · 

reply

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: uros@sir-mag.com
  Subject: Re: Recursion in plpgsql
  In-Reply-To: <93652058190.20020330233715@sir-mag.com>
  References: <93652058190.20020330233715@sir-mag.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