From: | Tim Wright <postgresql(at)icehawk(dot)freeserve(dot)co(dot)uk> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Anything like Oracle's "connect by" SQL? |
Date: | 2003-10-01 20:43:19 |
Message-ID: | 4.1.20031001213414.00b3ed58@pop.freeserve.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi,
Oracle has a rather handy system for recursing through a table hierarchy.
To give an example, if we had a table representing Companies, with three
fields: company_id, parent_company_id and company_name, you could use the
following SQL to get all parents (and parent of parents, etc) of company_id
1234 like this:
select company_name from Company
connect by company_id = prior parent_company_id
start with company_id = 1234
(My sincere apologies if I'm teaching people to suck eggs - this is my
first post to the list, so for all I know you're all Oracle gurus!)
Is there any kind of function like this in PostgreSQL, or other way to
easily simulate it? I'm currently designing a database which will require a
certain amount of parent-child relationships, and whilst in Oracle I know
the SQL would be simple, I'm not sure how easy it will be without using
"connect by"...
Any help gratefully received!
Cheers,
Tim.
From | Date | Subject | |
---|---|---|---|
Next Message | Nabil Sayegh | 2003-10-01 21:54:47 | Re: Anything like Oracle's "connect by" SQL? |
Previous Message | Manfred Koizar | 2003-10-01 18:03:23 | Re: SELECT syntax question - combining COUNT and DISTINCT |