Re: Is it possible to make the order of output the same as the order of input parameters?

Поиск
Список
Период
Сортировка
От A. Kretschmer
Тема Re: Is it possible to make the order of output the same as the order of input parameters?
Дата
Msg-id 20100602120007.GB5335@a-kretschmer.de
обсуждение исходный текст
Ответ на Re: Is it possible to make the order of output the same as the order of input parameters?  (Stephen Frost <sfrost@snowman.net>)
Список pgsql-general
In response to Stephen Frost :
> * m. hvostinski (makhvost@gmail.com) wrote:
> > I have a simple query like:
> >
> > SELECT * FROM customer WHERE id IN (23, 56, 2, 12, 10)
> >
> > The problem is that I need to retrieve the rows in the same order as the set
> > of ids provided in the select statement. Can it be done?
>
> Not very easily.  My first thought would be doing something like:
>
> SELECT
>   customer.*
> FROM
>   customer a
>   JOIN (VALUES (1,23),(2,56),(3,2),(4,12),(5,10)) b
>     ON (a.id = b.column2)
> ORDER BY b.column1

Nice ;-)

Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

В списке pgsql-general по дате отправления:

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: How do we get the Client-Time and Server-Time from psql ?
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: create index concurrently - duplicate index to reduce time without an index