Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 73A3C6337EE for ; Mon, 19 Apr 2010 04:38:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46226-02 for ; Mon, 19 Apr 2010 07:38:08 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id E0F2B63247C for ; Mon, 19 Apr 2010 04:38:08 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id o3J7c6QX075410 for ; Mon, 19 Apr 2010 04:38:06 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id o3J7N97j070019 for pgsql-general@postgresql.org; Mon, 19 Apr 2010 04:23:09 -0300 (ADT) (envelope-from news) From: cojack X-Newsgroups: pgsql.general Subject: Ltree - how to sort nodes on parent node Followup-To: pgsql.general Date: Mon, 19 Apr 2010 09:23:09 +0200 Organization: Aichra.pl Lines: 46 Message-ID: Reply-To: xcojack@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: usenet@news.hub.org User-Agent: KNode/4.4.2 To: pgsql-general@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.801 tagged_above=-10 required=5 tests=BAYES_50=0.8, FREEMAIL_FROM=0.001, T_RP_MATCHES_RCVD=-0.01, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201004/600 X-Sequence-Number: 161798 Hello, Im here because Oleg Bartunov invite me to this mailing list. Im searching for help with ltree module, in todo list (in this module) is Better documentation, since 2003 year, no one make something more for this. Whats is the problem? With example from manual about ltree, we have some data in our table, now add some row to table for Science node, and we will have something like this: id | path | sort ----+-----------------------------------------------+------ 1 | Top | 1 2 | Top.Science | 1 3 | Top.Science.Astronomy | 1 4 | Top.Science.Astronomy.Astrophysics | 1 5 | Top.Science.Astronomy.Cosmology | 2 6 | Top.Hobbies | 2 7 | Top.Hobbies.Amateurs_Astronomy | 2 8 | Top.Collections | 3 9 | Top.Collections.Pictures | 1 10 | Top.Collections.Pictures.Astronomy | 1 11 | Top.Collections.Pictures.Astronomy.Stars | 1 12 | Top.Collections.Pictures.Astronomy.Galaxies | 2 13 | Top.Collections.Pictures.Astronomy.Astronauts | 3 15 | Top.Science.Programing | 3 Sort column, is added by my self, because Im trying to sort those columns, but I don't know how. depesz from irc show me example how to sort this data with creating ordering column in the fly: WITH RECURSIVE rec AS ( SELECT *, btrim(to_char( sort, '0000000' )) AS ordering FROM tree WHERE nlevel(path) = 1 UNION ALL SELECT t2.*, t1.ordering || '/' || btrim(to_char( t2.sort, '0000000' )) AS ordering FROM rec t1, tree t2 WHERE t1.path @> t2.path AND nlevel(t1.path) + 1 = nlevel(t2.path) ) SELECT id, subpath(path, -1) AS title, nlevel(path) AS depth, sort FROM rec ORDER BY ordering; But I'm not sure it's the best way to sort this columns, so Im wrinting here for help and some examples, or improve the ltree manual with more example. -- Regards, cojack.