Re: Sorting with materialized paths

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Ovid <curtis_ovid_poe(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Sorting with materialized paths
Date: 2010-05-10 21:22:20
Message-ID: 73CF661F-9445-4130-91AC-BB2BEEBD0E0E@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10 May 2010, at 20:06, Greg Stark wrote:

> On Sun, May 9, 2010 at 4:47 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Ovid <curtis_ovid_poe(at)yahoo(dot)com> writes:
>>> My apologies. This isn't PG-specific, but since this is running on PostgreSQL 8.4, maybe there are specific features which might help.
>>> I have a tree structure in a table and it uses materialized paths to allow me to find children quickly. However, I also need to sort the results depth-first, as one would expect with threaded forum replies.
>>
>> I think contrib/ltree might help you here. However, it seems to sort
>> node names textually rather than numerically, so you might need to
>> change it a bit for your own purposes.
>>
>
> That's rather unfortunate. Ltree is awfully convenient and it would be
> nice to be able to use it.
>
> If you just used plain Postgres arrays of integers you would get the
> sorting you want. But you lose all the useful ltree operators for
> trees.

I recall from the docs that you can create arrays of ltrees. It has some special operators for that. I couldn't figure out what the use case for those ltree-arrays was (the docs are rather sparse), but it might just be what you're looking for.

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.

!DSPAM:737,4be8791c10411720337464!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2010-05-10 21:34:58 Re: Finding rows with text columns beginning with other text columns
Previous Message Andy Colson 2010-05-10 21:15:12 Re: How to do pg_dump + pg_restore within Perl script?