pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Eckermann <jeckermann@verio.net>
To: Juan Jose Comellas <juanjo@comellas.org>
To: pgsql-general@postgresql.org
Subject: Re: Recursive queries
Date: Fri, 21 Sep 2001 13:46:35 -0500
Message-ID: <02f301c142cd$bd6bebe0$279c10ac@INTERNAL> (raw)
References: <200109211614.f8LGEZk21143@mens.hq.novamens.com>

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@comellas.org>
To: <pgsql-general@postgresql.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@comellas.org)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>




view thread (27+ messages)  latest in thread

Message-ID: <02f301c142cd$bd6bebe0$279c10ac@INTERNAL>
Permalink:  ../02f301c142cd$bd6bebe0$279c10ac@INTERNAL/
Also on:    postgresql.org/message-id/02f301c142cd$bd6bebe0$279c10ac@INTERNAL

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: jeckermann@verio.net, juanjo@comellas.org
  Subject: Re: Recursive queries
  In-Reply-To: <02f301c142cd$bd6bebe0$279c10ac@INTERNAL>
  References: <200109211614.f8LGEZk21143@mens.hq.novamens.com> <02f301c142cd$bd6bebe0$279c10ac@INTERNAL>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox