Obscure behavior of ORDER BY

From: Tambet Matiisen <tambet(dot)matiisen(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Obscure behavior of ORDER BY
Date: 2011-03-21 09:29:18
Message-ID: 4D871A6E.6050608@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi everyone!

I recently noticed obscure behavior of ORDER BY. Consider this example:

select email from
(
select '@'::text as email
union all
select '.'::text as email
) a
order by email;

The result is:
email
-------
.
@
(2 rows)

This is all normal - I expect, that dot is smaller than ampersand. But
if I add anything after dot, the order is reversed:

select email from
(
select '@'::text as email
union all
select '.m'::text as email
) a
order by email

The result is:
email
-------
@
.m
(2 rows)

Why is this happening? As dot is smaller than ampersand, anything after
dot shouldn't matter.

I'm using PostgreSQL 8.4.7 on 32-bit Debian.

Thanks in advance,
Tambet

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rob Sargent 2011-03-23 16:52:07 xml2 support
Previous Message Good, Thomas 2011-03-17 17:27:22 Re: Bizarreness at A2 Hosting