Re: DISTINCT ON changes sort order on its own it seems

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Reichstadt <info(at)apfeltaste(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: DISTINCT ON changes sort order on its own it seems
Date: 2013-04-28 03:03:26
Message-ID: 2939.1367118206@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alexander Reichstadt <info(at)apfeltaste(dot)net> writes:
> following a query:
> SELECT DISTINCT ON (msgid) msgid FROM (SELECT refid_messages as msgid FROM messagehistorywithcontent WHERE 1=1 AND (lower(ARRAY_TO_STRING(ARRAY[login,firstname,lastname,content,msgtitle], ' ')) LIKE '%gg%') ORDER BY messagekind DESC) as foo

> This query rearranges the sort order though.

It's perfectly within its rights to emit the rows in any order
whatsoever, because you wrote no ORDER BY in the outer query level.
The ORDER BY in the sub-select is not binding on the outer query.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2013-04-28 04:16:54 Re: Optimizing bulk update performance
Previous Message Yang Zhang 2013-04-27 20:10:24 Re: Basic question on recovery and disk snapshotting