Re: Stable sort?

From: Ron Mayer <rm_pg(at)cheapcomplexdevices(dot)com>
To: redhog <redhog(at)redhog(dot)org>
Subject: Re: Stable sort?
Date: 2006-11-08 00:43:49
Message-ID: 45512845.9080708@cheapcomplexdevices.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

redhog wrote:
> Is sorting in PostgreSQL stable over subqueries, that is, is
>
> select * from (select * from A order by x) as B order by y;
>
> equivalent with
>
> select * from A order by y, x;

Seems as easy to try as to guess.

If I did this query right, it seems not.

select * from (select random()>0.5 as a, random()>0.5 as b from generate_series(1,10) order by a) as x order by b;
a | b
---+---
f | t
f | f
f | f
f | f
f | t
f | f
t | t
t | t
t | t
t | f
(10 rows)

OTOH, HEY, why isn't that result ordered by 'b' instead of by 'a' (or am I misreading my query or the results)?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2006-11-08 00:50:52 A couple more PostgreSQL C questions
Previous Message Wei Weng 2006-11-08 00:28:58 Question on inserting and querying at the same time.