Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4CAE0632E54 for ; Tue, 20 Apr 2010 07:08:32 -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 26825-10 for ; Tue, 20 Apr 2010 10:08:22 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id C723E6324A1 for ; Tue, 20 Apr 2010 07:08:21 -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 o3KA8IC1014253 for ; Tue, 20 Apr 2010 07:08:18 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id o3K9xkAU008597 for pgsql-general@postgresql.org; Tue, 20 Apr 2010 06:59:46 -0300 (ADT) (envelope-from news) From: cojack X-Newsgroups: pgsql.general Subject: Re: Ltree - how to sort nodes on parent node Followup-To: pgsql.general Date: Tue, 20 Apr 2010 11:59:44 +0200 Organization: Aichra.pl Lines: 67 Message-ID: References: <59670B22-30CB-4E6E-83C8-C1D1036C9B2A@solfertje.student.utwente.nl> 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/649 X-Sequence-Number: 161847 > Alban Hertroys wrote: > > > Aha, looks like you want to sort each tree level by some user-specified > order. > > You should realise that ltree was contributed before Postgres supported > (recursive) CTE's. If you're using ltree in combination with recursive > CTE's you're doing twice the work that you need to do - ltree was created > as a means to make recursive queries possible in the first place. > > I think you have basically two ways to go about this: > > 1). The way you're doing this in your new examples should work, although > I'd probably make the ordering numbers part of the category names and > split those off when I read them. For example: > 27 | 1|Top > 28 | 1|Top.1|Science > 29 | 1|Top.2|Hobby > 30 | 1|Top.3|Colors > 31 | 1|Top.1|Science.1|Physics > 32 | 1|Top.1|Science.2|Chemistry > 33 | 1|Top.1|Science.3|Biology > 34 | 1|Top.1|Science.4|History > 35 | 1|Top.2|Hobby.1|Fishing > 36 | 1|Top.2|Hobby.2|Football > 37 | 1|Top.3|Colors.1|Black > 38 | 1|Top.3|Colors.2|Red > 39 | 1|Top.3|Colors.3|Blue > 40 | 1|Top.1|Science.5|Archeology > 41 | 1|Top.2|Hobby.3|Swimming > 42 | 1|Top.3|Colors.4|Gray > 43 | 1|Top.3|Colors.5|Purple > 44 | 1|Top.3|Colors.6|Brown > 45 | 1|Top.2|Hobby.4|Climbing > > > Alban Hertroys > > -- > Screwing up is an excellent way to attach something to the ceiling. > > > !DSPAM:737,4bcd773910411833268189! > > > My and your first example doesn't work fine at all, why? Becouse when we add more thank 10 sub nodes in some node, the 10 node will not be after 9, but after 1 before 2, and this is not good idea to set sort in path. I think the best idea for this will be create other column, with also ltree data type and stored inside a sort/ordering data. Like: 1 1.1 1.1.1 1.1.2 1.1.3 And while selected it from table, just cast it to int. I'll check this and his performance after I return from work. I am not interested about recursive queries, i think this kill ltree idea. -- Regards, cojack.