pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathaniel Price <nprice@tesseract.net>
To: pgsql-general@postgresql.org
Subject: Reordering results for a report
Date: Fri, 12 Dec 2003 10:37:27 -0800
Message-ID: <3FDA0AE7.60200@tesseract.net> (raw)

I'm new to this list, so I'm not sure if this is the right place to post 
this. If not, please direct me to where it would be better to post it.

Anyway, I'm creating a report generation tool of sorts in PHP for a 
database. As part of this report generation tool, I'd like to allow the 
user to reorder these results arbitrarily. In other words:

id | offer
---+------------
1  | Offer 1
2  | Offer 2
3  | Offer 3

could become

id | offer
---+------------
3  | Offer 3
1  | Offer 1
2  | Offer 2

However, I don't see any way of reordering the results arbitrarily, 
short of creating a table that maps the id numbers to an arbitrary sort 
order, joining them and doing an ORDER BY on the sort order numbers, 
like so:

id | offer     | sort
---+-----------+------
3  | Offer 3   | 1
1  | Offer 1   | 2
2  | Offer 2   | 3

The problems that I have with this solution are
--The sort order would be unique for anybody who uses the system, in 
other words, one user may sort one way, and another user another way, 
and perhaps simultaneously. I could fix this by using an additional 
session identifier in the sort table, but that leads me to the next 
problem...
--I'd have to garbage collect this data everytime I'm finished with it, 
and since it's likely to only be used once for the actual report 
generation and then discarded, it seems like a waste of effort.

So is there a way to make a query where I can sort arbitrarily without 
having to create additional data in the database?

Thanks for your attention.

-- 
___________________________
Nathaniel Price
http://www.tesserportal.net
Webmaster





view thread (11+ messages)  latest in thread

Message-ID: <3FDA0AE7.60200@tesseract.net>
Permalink:  ../3FDA0AE7.60200@tesseract.net/
Also on:    postgresql.org/message-id/3FDA0AE7.60200@tesseract.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: nprice@tesseract.net, pgsql-general@postgresql.org
  Subject: Re: Reordering results for a report
  In-Reply-To: <3FDA0AE7.60200@tesseract.net>
  References: <3FDA0AE7.60200@tesseract.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox