X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B1FCED1CC97 for ; Sun, 14 Dec 2003 02:39:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 59608-09 for ; Sat, 13 Dec 2003 22:39:24 -0400 (AST) Received: from smtp.istop.com (dci.doncaster.on.ca [66.11.168.194]) by svr1.postgresql.org (Postfix) with ESMTP id 6C28ED1CB3F for ; Sat, 13 Dec 2003 22:39:14 -0400 (AST) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by smtp.istop.com (Postfix) with ESMTP id AD9B036C97; Sat, 13 Dec 2003 21:39:08 -0500 (EST) Received: from localhost ([127.0.0.1] helo=stark.dyndns.tv ident=foobar) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1AVMA0-00066j-00; Sat, 13 Dec 2003 21:39:08 -0500 To: pgsql-general@postgresql.org Subject: Re: Reordering results for a report References: <3FDA0AE7.60200@tesseract.net> In-Reply-To: <3FDA0AE7.60200@tesseract.net> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 13 Dec 2003 21:39:08 -0500 Message-ID: <87u144w2b7.fsf@stark.dyndns.tv> Lines: 34 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/748 X-Sequence-Number: 54142 Nathaniel Price writes: > 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 You could do something like select id,offer from tab order by case when id = 3 then 1 when id = 1 then 2 when id = 2 then 3 end But a) if there are thousands of records you're going to have rather a huge query and b) where are you going to store this ordering? -- greg