Re: Problem with result ordering

From: Tommy Gildseth <tommy(at)gildseth(dot)com>
To:
Cc: Thorsten Körner <t(dot)koerner(at)cappuccinosoft(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with result ordering
Date: 2007-01-25 19:37:30
Message-ID: 45B906FA.5050208@gildseth.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Thorsten =?iso-8859-1?q?K=F6rner?= <t(dot)koerner(at)cappuccinosoft(dot)de> writes:
>
>> select m_id, m_u_id, m_title, m_rating from tablename where m_id in (26250,
>> 11042, 16279, 42197, 672089);
>>
> 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.
>

Or a variant of this,
SELECT m_id, m_u_id, m_title, m_rating from tablename where m_id in (26250,
11042, 16279, 42197, 672089) ORDER BY m_id=26250, m_id=11042,
m_id=16279, m_id=42197, m_id=672089;

--
Tommy Gildseth
http://www.gildseth.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Furesz Peter 2007-01-25 19:46:39 Loop plpgsql recordset
Previous Message Bruce Momjian 2007-01-25 19:34:40 Re: sequence increment jumps?