X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7410F11F694B for ; Fri, 7 Apr 2006 04:28:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38830-10 for ; Fri, 7 Apr 2006 04:28:22 -0300 (ADT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E6AB511F6947 for ; Fri, 7 Apr 2006 04:28:23 -0300 (ADT) Received: from www.kavod.com (www.kavod.com [216.133.73.134]) by svr4.postgresql.org (Postfix) with ESMTP id 219FD5AF989 for ; Fri, 7 Apr 2006 07:28:24 +0000 (GMT) Received: from lx4.kavod.com (lx4.kavod.com [71.236.193.93]) by www.kavod.com (8.13.1/8.13.1) with ESMTP id k377RieK025890 for ; Fri, 7 Apr 2006 03:27:49 -0400 Received: from lx4.kavod.com (localhost.localdomain [127.0.0.1]) by lx4.kavod.com (8.13.6/8.13.4) with ESMTP id k377SF49004502 for ; Fri, 7 Apr 2006 00:28:15 -0700 Received: from localhost (localhost [[UNIX: localhost]]) by lx4.kavod.com (8.13.6/8.13.6/Submit) id k377SFMQ004501 for pgsql-sql@postgresql.org; Fri, 7 Apr 2006 00:28:15 -0700 From: Daniel Browning Organization: Kavod Technologies To: pgsql-sql@postgresql.org Subject: Modeling trees with Nested Sets and Nested Intervals Date: Fri, 7 Apr 2006 00:28:15 -0700 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200604070028.15476.db@kavod.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200604/52 X-Sequence-Number: 24861 I would like to model some hierarchical (tree) data in PostgreSQL. Where can I find high quality Nested Set (or Nested Interval) source code and documentation? I know this question gets asked a lot. To illustrate the point, here is just one thread from each of the last five years: http://archives.postgresql.org/pgsql-sql/2001-08/msg00242.php http://archives.postgresql.org/pgsql-sql/2002-05/msg00270.php http://archives.postgresql.org/pgsql-general/2003-12/msg00247.php http://archives.postgresql.org/pgsql-general/2004-03/msg00804.php http://archives.postgresql.org/pgsql-sql/2005-04/msg00231.php Luckily, no one has asked this question yet in 2006. :-) I've been scouring the Net for a while now, but I hope there are more resources out there that I haven't stumbled onto yet. Here's what I've found so far: * Static Hierarchies and Binary Fractions in PostgreSQL, by Michael Glaesemann http://www.grzm.com/fornow/archives/2004/07/10/static_hierarchies This is the most complete out-of-the-box solution I've found. It uses binary fractions and nested intervals (well, Manfred Koizar says its more of a Materialized Path model). Lots of handholding, documentation, and functions for everything you would want to do to a tree. Limited to 61 nodes in the first branch, plus other limitations. * Modified "m-vgID method", by OpenACS http://cvs.openacs.org/cvs/openacs-4/packages/acs-kernel/sql/postgresql/ Reported to support 2^31 nodes per level, uses bitstring encoding. * m-vgID method, by Miguel Sofer http://www.utdt.edu/~mig/sql-trees/ Uses base 159 encoding (all latin1 chars). * Joe Celko's SQL for Smarties: Advanced SQL Programming, 2nd Edition Highly recommended book. Joe also has a few articles and mailing list posts floating around the web: http://www.dbmsmag.com/9603d06.html http://archives.postgresql.org/pgsql-sql/2001-11/msg00004.php http://archives.postgresql.org/pgsql-sql/2003-01/msg00459.php To be clear, I'm not looking for an adjacency model, materialized path model, contrib/ltree, or connect by. Other resources that have been helpful: http://troels.arvin.dk/db/rdbms/links/#hierarchical http://groups.google.com/group/comp.databases.theory/msg/7b772060322df739 Maybe all this would make a good project on pgfoundry. -- Daniel Browning - Kavod Technologies. Random Fortune: To Perl, or not to Perl, that is the kvetching. -- Larry Wall in <199801200310.TAA11670@wall.org>