pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tambet Matiisen <tambet.matiisen@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Obscure behavior of ORDER BY
Date: Mon, 21 Mar 2011 11:29:18 +0200
Message-ID: <4D871A6E.6050608@gmail.com> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <4D871A6E.6050608@gmail.com>
Permalink:  ../4D871A6E.6050608@gmail.com/
Also on:    postgresql.org/message-id/4D871A6E.6050608@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tambet.matiisen@gmail.com
  Subject: Re: Obscure behavior of ORDER BY
  In-Reply-To: <4D871A6E.6050608@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox