Received: from mail.estadistica.unam.mx (IDENT:david@mail.estadistica.unam.mx [132.248.39.253]) by hub.org (8.9.1/8.9.1) with ESMTP id LAA06407 for ; Tue, 12 Jan 1999 11:53:34 -0500 (EST) (envelope-from david@estadistica.unam.mx) Received: from localhost (david@localhost) by mail.estadistica.unam.mx (8.8.7/8.8.5) with SMTP id KAA10189; Tue, 12 Jan 1999 10:50:36 -0600 Date: Tue, 12 Jan 1999 10:50:35 -0600 (CST) From: David Martinez Cuevas X-Sender: david@mail To: Neil Burrows cc: pgsql-sql@postgreSQL.org Subject: Re: [SQL] A path through a tree In-Reply-To: <000c01be3e38$a1d4a170$c6cb9284@towhee.gssec.bt.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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".