From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gregory Stark <stark@enterprisedb.com>
Cc: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sql ORDER BY and ASC/DESC question
Date: Wed, 30 Jan 2008 13:00:29 -0500
Message-ID: <14687.1201716029@sss.pgh.pa.us> (raw)
In-Reply-To: <87tzkvbfr6.fsf@oxford.xeocode.com>
References: <aa457f86948348248e93c6fc38b4b1f6@pobox.sk>
<20080130104226.GF26490@a-kretschmer.de>
<87tzkvbfr6.fsf@oxford.xeocode.com>
Gregory Stark <stark@enterprisedb.com> writes:
> If you're not concerned with the planner being able to find indexes to satisfy
> these orderings (ie, you don't mind always doing a sort) you could do
> something like:
> ORDER BY
> CASE ?
> WHEN 1 THEN name ASC
> WHEN 2 THEN name DESC
> WHEN 3 THEN height ASC
> WHEN 4 THEN height DESC
> ELSE id ASC
> END
Uh, no, putting the ASC/DESC decoration inside a CASE like that is not
gonna work --- it's only allowed at the top level of an ORDER BY clause.
For numerical sort keys you can cheat by using "-x" in place of
"x DESC", but I'm not aware of any equivalent hack for text keys.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, stark@enterprisedb.com, andreas.kretschmer@schollglas.com
Subject: Re: Sql ORDER BY and ASC/DESC question
In-Reply-To: <14687.1201716029@sss.pgh.pa.us>
* 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