Re: Recursive queries

From: "Jeff Eckermann" <jeckermann(at)verio(dot)net>
To: "Juan Jose Comellas" <juanjo(at)comellas(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Recursive queries
Date: 2001-09-21 18:46:35
Message-ID: 02f301c142cd$bd6bebe0$279c10ac@INTERNAL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There was a detailed post by Joe Celko not long ago, which discussed how to
handle trees in SQL. I suggest you look at the list archives to find this.

----- Original Message -----
From: "Juan Jose Comellas" <juanjo(at)comellas(dot)org>
To: <pgsql-general(at)postgresql(dot)org>
Sent: Friday, September 21, 2001 11:14 AM
Subject: [GENERAL] Recursive queries

> I have a database with the following fields:
>
> product_id INTEGER
> parent_id INTEGER
> name VARCHAR(64)
>
> The idea is that it will store a tree of products and its subproducts. Any
> row whose parent_id is NULL will be assumed to be a root product (i.e. top
> level).
>
> This means I will need to process recursively, with some sort of reference
to
> parent_id passing through layers of recursion.
>
> However, I want to save on database queries and do a "SELECT *", then
fetch
> each row on the results recursively, to build the tree. The idea is to
only
> have to do one db query.
>
> Does anyone have any idea how this can be done in PostgreSQL? Both Oracle
and
> DB2 support this with their own proprietary syntax.
>
>
> --
> Juan Jose Comellas
> (juanjo(at)comellas(dot)org)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Pilosov 2001-09-21 19:14:57 Re: Postgres 7.1.3 on OpenBSD 2.9?
Previous Message Peter Eisentraut 2001-09-21 18:45:46 Re: Postgres 7.1.3 on OpenBSD 2.9?