Re: Reordering results for a report - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Reordering results for a report
Date
Msg-id 20031213234732.GA30707@wolff.to
Whole thread Raw
In response to Re: Reordering results for a report  (Nathaniel Price <nprice@tesseract.net>)
Responses Re: Reordering results for a report (follow-up)  (Nathaniel Price <nprice@tesseract.net>)
List pgsql-general
On Fri, Dec 12, 2003 at 14:40:34 -0800,
  Nathaniel Price <nprice@tesseract.net> wrote:
> Sorry, that's not really what I'm looking for. When I said that the sort
> order could be arbitrary, I meant /arbitrary/. As in "no amount of ORDER
> BYs will save me from this one" arbitrary; the records could be in any
> order the user specifies.
>
> The idea is that in PHP I'd be using an array to keep track of the
> custom order that the results should be returned in, using the array
> index to store the sorting order and the values to store the table's
> primary key, like so (note that this isn't the code I'm using, it's just
> an example):
>
> <?php
> $sort[0] = 3; //First record to return (3 is the primary key of the record)
> $sort[1] = 1; //Second record to return
> $sort[2] = 2; //Third record to return
> ... //and so on.
> ?>

It would be possible to use this array in a query, but this wouldn't
work well for large data sets as you would be sending the whole array
back and forth a lot. Presumably the reason you want to do the sort
in the database is because the dataset is large enough that you don't
want to buffer the data in PHP in the first place.

I think the temp table solution won't be that simple either. You will
need connection pooling and some way to keep requests from the same
web session using the same postgres session.

You may want to use regular tables which are named by session id and
the have some clean up process that removes tables that are no longer
needed.

pgsql-general by date:

Previous
From: Andrew Rawnsley
Date:
Subject: Re: make error Mac OS X (ar: illegal option -- s)
Next
From: Bruno Wolff III
Date:
Subject: Re: Delete all records NOT referenced by Foreign Keys