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

Поиск
Список
Период
Сортировка
От Andreas Kretschmer
Тема Re: Is it possible to make the order of output the same as the order of input parameters?
Дата
Msg-id 20100602114521.GA19564@tux
обсуждение исходный текст
Ответ на Is it possible to make the order of output the same as the order of input parameters?  ("m. hvostinski" <makhvost@gmail.com>)
Список pgsql-general
m. hvostinski <makhvost@gmail.com> wrote:

> Hi,
>
> 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?

No. The only way is:

select * from ... where id in (...) order by case when id=23 then 1,
case when id=56 then 2 end, case when id=2 then 3 end, ...

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

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

Предыдущее
От: Sam Mason
Дата:
Сообщение: Re: Is it possible to make the order of output the same as the order of input parameters?
Следующее
От: Stephen Frost
Дата:
Сообщение: Re: How do we get the Client-Time and Server-Time from psql ?