Re: ORDER BY FIELD feature

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Kevin Reynolds <kreynolds98092(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ORDER BY FIELD feature
Date: 2008-05-12 09:27:17
Message-ID: 48280D75.4070902@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kevin Reynolds a écrit :
> Does postgresql have something similar to the ORDER BY FIELD feature
> found in MySQL?
>
> Something like ORDER BY FIELD(ID, 10, 2, 56, 40);
>
> It is listed here: http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html
>
> I am using the Sphinx Search program, www.sphinxsearch.com
> <http://www.sphinxsearch.com>, and it returns a list of IDs ordered by
> relevance. I take the array it gives me and create a comma separated
> list which is used in a postgres query using the WHERE "ID" IN (10, 2,
> 56, 40) statement. I would like to order the result by the order of the
> list.
>

ORDER BY ID=10 DESC, ID=2 DESC, ID=56 DESC, ID=40 DESC
is the only way, AFAIK.

Regards.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Abdus Samad Ansari 2008-05-12 09:58:17 PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server:
Previous Message Pavel Stehule 2008-05-12 09:12:07 Re: Returning RECORD from PGSQL without custom type?