Re: [SQL] A path through a tree - Mailing list pgsql-sql

From David Martinez Cuevas
Subject Re: [SQL] A path through a tree
Date
Msg-id Pine.LNX.3.96.990112104143.9826A-100000@mail
Whole thread Raw
In response to A path through a tree  ("Neil Burrows" <maillist@remo.demon.co.uk>)
List pgsql-sql

Hi Neil.

On Tue, 12 Jan 1999, Neil Burrows wrote:
> Hi,
>
> OK, I have a feeling that this not something that can be done with SQL but I
> may as well give it a shot.

Actually, as you should know, postgresql doesn't have a procedural
language... in this problem it is necessary to use it... but you can use
libpq or any other interface to do it.

> Say you have a table with the following columns:
>
> id     int4 NOT NULL UNIQUE
> parent int4
> value  varchar(8)
>

Here a is a sample and bad written funtion that can help you.
As you will see I didn't compiled it, and there is a lot of code you
should still write to use it.... it's just an idea:


#include "whatever_you_need";

...
   char * look_for_parent ( char *);

   function look_for_parent ( char *leaf )
   {  if (leaf == NULL) return "This is the root: $leaf";
      parent = PQ_EXEC($YOUR_CONN,"select parent from table where values = $leaf")$
   print ("\nFor the leaf %s the parent is %s",leaf,parent);
   return ( look_for_parent (parent));
   }
...


As you can see it pretends to be a C code contaminated with PHP  ; )

Good luck


David Martinez Cuevas.mx

            "Eat Linux, Drink Linux... SMOKE LINUX".


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: storing strings with embedded '\'
Next
From: Greg Youngblood
Date:
Subject: RE: [SQL] SELECT... BETWEEN 'P' and 'Z'