Re: [SQL] A path through a tree

From: David Martinez Cuevas <david(at)estadistica(dot)unam(dot)mx>
To: Neil Burrows <maillist(at)remo(dot)demon(dot)co(dot)uk>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] A path through a tree
Date: 1999-01-12 16:50:35
Message-ID: Pine.LNX.3.96.990112104143.9826A-100000@mail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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".

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Stephens 1999-01-12 19:09:55 Re: [SQL] A path through a tree
Previous Message Tom Lane 1999-01-12 15:17:27 Re: storing strings with embedded '\'