473,806 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

functionality like Oracle's "connect by"

I know this question has been discussed, probably multiple times, but I
can't seem to access archives.postgr esql.org today....

I need to select all the rows in a table with two fields: parent_id and
child_id that participate in the same logical "tree". In other words,
given an id value, I want to find where child_id = my-value, and then
retrieve the values in the tree above it.

The functionality I'm looking for is essentially the Oracle "connect
by". Does anything like this exist for postgresql? If not, does anybody
have a clever solution? (My not-so-clever first pass involved recursing
in my Java program, but the stack-space-abuse police are knocking on my
door....)

Again, apologies for asking something that's probably already been
discussed ad nauseum on this list...

- DAP
=============== =============== =============== =========
David Parker Tazz Networks (401) 709-5130


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 1838

"David Parker" <dp*****@tazzne tworks.com> writes:
The functionality I'm looking for is essentially the Oracle "connect
by". Does anything like this exist for postgresql?


Yes. In the contrib directory of the source is a directory named "tablefunc" .
If you've installed from an distribution you might like for a
postgresql-contrib package or something like that.

It has a function that tries to do what you want:
connectby(text relname, text keyid_fld, text parent_keyid_fl d
[, text orderby_fld], text start_with, int max_depth
[, text branch_delim])
- returns keyid, parent_keyid, level, and an optional branch string
and an optional serial column for ordering siblings
- requires anonymous composite type syntax in the FROM clause. See
the instructions in the documentation below.
I've never tried it though.

--
greg
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #2
David,

I suggest our search on postgresql resources:
http://www.pgsql.ru/db/pgsearch/inde...t+by%22+oracle
Oleg

On Mon, 30 Aug 2004, David Parker wrote:
I know this question has been discussed, probably multiple times, but I
can't seem to access archives.postgr esql.org today....

I need to select all the rows in a table with two fields: parent_id and
child_id that participate in the same logical "tree". In other words,
given an id value, I want to find where child_id = my-value, and then
retrieve the values in the tree above it.

The functionality I'm looking for is essentially the Oracle "connect
by". Does anything like this exist for postgresql? If not, does anybody
have a clever solution? (My not-so-clever first pass involved recursing
in my Java program, but the stack-space-abuse police are knocking on my
door....)

Again, apologies for asking something that's probably already been
discussed ad nauseum on this list...

- DAP
=============== =============== =============== =========
David Parker Tazz Networks (401) 709-5130
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Regards,
Oleg
_______________ _______________ _______________ _______________ _
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: ol**@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2588
by: Jamie Burns | last post by:
I have written a Windows Service to access an Oracle database. A dialog box appears, prompting for user logon if the database is not accessable due to network problems I just want the connection to fail quietly. Here's a little code snippet. // Create workspace. CDaoWorkspace wspCurrent; wspCurrent.Create("MyWorkspace","MyUser","MyPasswordUser");
1
17103
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't get it handled solving that problem. Neither with oracle sql or SQL1999 syntax!
12
3739
by: Mikito Harakiri | last post by:
I wonder if WITH RECURSIVE MaryAncestor(anc,desc) AS ( (SELECT parent as anc, child as desc FROM ParentOf WHERE desc = "Mary") UNION (SELECT A1.anc, A2.desc FROM MaryAncestor A1, MaryAncestor A2 WHERE A1.desc = A2.anc) ) SELECT anc FROM MaryAncestor
2
5797
by: Hunter | last post by:
when I firstly ran "connect to dbname" command after "db2start", it spent me about 10 mins. I saw a process named "db2sync" that used 700M memory. The OS is Linux Advanced Server V2.1, Database is V8.1.5. The machine is Compaq ProLiant 8000, 1G Mem. How can I do? thanks..
3
1767
by: EYIII | last post by:
Is it possible to retrieve the "created by" identity and "modified by" identity for a file (e.g. word doc, .pdf, report, etc) using .NET?
0
2812
by: chico_001 | last post by:
I am doing some database testing and when I found a problem with the case sensitivity of "CONNECT TO". When "CONNECT to" is written with capital and small letters, a new db is not dropped and recreated. e.g. CONNECT to db; Note lowercase "to". If this is changed to CONNECT TO db; then newdb works
15
1907
by: wizofaus | last post by:
I have a chunk of code which is essentially IDbCommand cmd = db.CreateCommand(); cmd.CommandText = "SELECT X, Y, Count(*) FROM Foo WHERE Z = 1 GROUP BY X, Y"; using (IDataReader reader = cmd.ExecuteReader()) while (reader.Read()) { // grab values from query }
3
4789
by: cberthu | last post by:
Hi all, Is it possible to have two connects in the same rexx script to different DB's? I have to get data form on DB (with specifics selects and filter out some values with RExx) and save the results into another DB? I know from Wscripts and MS-Sql that you can build just two objects but I did not see something like that in REXX. Thanks in advance for your help
4
4476
by: Adisc | last post by:
Hi, How can I run a query to fetch the hierarchy without using the command - connect by prior? I want to use this query by BO, which does not support the connect byqstart with option. thanks
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.