Re: Problem with result ordering

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Problem with result ordering
Дата
Msg-id 20467.1169743416@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Problem with result ordering  (Thorsten Körner <t.koerner@cappuccinosoft.de>)
Ответы Re: Problem with result ordering  (Tommy Gildseth <tommy@gildseth.com>)
Список pgsql-general
Thorsten =?iso-8859-1?q?K=F6rner?= <t.koerner@cappuccinosoft.de> writes:
> select m_id, m_u_id, m_title, m_rating from tablename where m_id in (26250,
> 11042, 16279, 42197, 672089);

> I wonder, how it is possible, to retrieve the results in the same order, as
> queried in the list.

You could rewrite the query as

select ... from tablename where m_id = 26250
union all
select ... from tablename where m_id = 11042
union all
select ... from tablename where m_id = 16279
union all
select ... from tablename where m_id = 42197
union all
select ... from tablename where m_id = 672089

This isn't guaranteed by the SQL spec to produce the results in any
particular order either; but there's no good reason for PG to rearrange
the order of the UNION arms, whereas there are plenty of good reasons to
try to optimize fetching of individual rows.

            regards, tom lane

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

Предыдущее
От: Inoqulath
Дата:
Сообщение: Re: SQL Newbie Question
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: Problem with result ordering