pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Douglas Trainor <trainor@uic.edu>
To: Gregory Brauer <greg@wildbrain.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Trees in SQL
Date: Fri, 24 May 2002 13:41:42 -0500
Message-ID: <3CEE8966.857521CF@uic.edu> (raw)
References: <3CEE818B.9020702@wildbrain.com>

If you're a book buyer, the one called "Joe Celko's SQL for Smarties: Advanced SQL Programming"
has a collection of tree/graph tricks.  About 50 pages are devoted to these three sections:

    Adjacency List Model of Trees
    Nested Set Model of Trees in SQL
    Graphs in SQL

Book distributors were trying to sell a preview edition of a book by
David Rozenshtein, et al called "Tree & Graph Processing in SQL" -- but something
fell through and the book apparently didn't come out.

Of course, it's more fun to not read a book and to try and implement a few toy tree/graph
things yourself.

    douglas

Gregory Brauer wrote:

> I hope this isn't an overly broad topic that ends up diverging into graph
> theory, but I have a tree structure of identical items (analogous to a
> filesystem directory tree) that I need to store in Postgres.  The
> "obvious" design is to give the table that will represent these objects
> a field identifying its "parent" that is a relation to the same table.
> However, this seems to make many common SQL queries rather difficult.
>
> What sort of strategies are best for storing tree structures in a
> relational database, and how would one structure SQL queries to find,
> say, "all of the children anywhere under this node", or to represent
> the condition "if this node is a child at any depth under this other
> node"?  Are there good strategies for preventing cycles?
>
> I'd appreciate any insights anyone can give.
>
> Thanks.
>
> Greg Brauer
> greg@wildbrain.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html




view thread (12+ messages)  latest in thread

Message-ID: <3CEE8966.857521CF@uic.edu>
Permalink:  ../3CEE8966.857521CF@uic.edu/
Also on:    postgresql.org/message-id/3CEE8966.857521CF@uic.edu

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: trainor@uic.edu, greg@wildbrain.com
  Subject: Re: Trees in SQL
  In-Reply-To: <3CEE8966.857521CF@uic.edu>

* 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