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

recursive seek...?

From: "Vazsonyi Peter[ke]" <neko(at)kornel(dot)szif(dot)hu>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: recursive seek...?
Date: 1998-03-16 14:37:50
Message-ID: Pine.A32.3.96.980316145935.20524B-100000@kornel.szif.hu (view raw or flat)
Thread:
Lists: pgsql-hackers
Kello!

I have a recusive relation, like this:
=> create table re( name text, oid parent);
and needed the name from a tuple, and the name of all parents...
i tryd some, like:
=> create function fullname(oid) returns text
-> as 'select fullname(re.parent) || re.name from re where re.oid=$1;'
-> language 'sql'; 
that isn't work. of course ;(

 i can get a name, and the parents oid, and the oid of parents parent etc...
 with _MORE_ queries. 

for example: 
=> select oid,* from re;
oid | name | parent
----+------+--------
5000|one   | (NULL or 0) 
5001|two   | 5000
5002|3d    | 5000
5003|4d    | 5002
i now the oid:5003. i need the name: "one/two/4d"
must i send thees queries to the backend? (in pseudo code):
$curr=5003
$fulln=''
while $curr do
  => SELECT name, parent FROM re WHERE oid=$curr;
  $fulln='$fulln/$name'; $curr=$parent;
enddo
so i liked send _ONLY_ 5003, and reveive in a trice the full name.
this time i can't this ;(

sprintf         ("`-''-/").___..--''"`-._            Error In
("%|s",          `6_ 6  )   `-.  (     ).`-.__.`)    Loading Object
"Petike"         (_Y_.)'  ._   )  `._ `. ``-..-'     line:3
/* Neko */     _..`--'_..-_/  /--'_.' ,'             Before /*Neko*/
 );           (il),-''  (li),'  ((!.-'	 see: http://lsc.kva.hu


In response to

pgsql-hackers by date

Next:From: Thomas G. LockhartDate: 1998-03-16 15:12:49
Subject: Re: [HACKERS] varchar() vs char16 performance
Previous:From: Bruce MomjianDate: 1998-03-16 14:33:21
Subject: Re: [HACKERS] Re: [PORTS] Port Bug Report: Grant select to other user

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