Re: Obscure behavior of ORDER BY

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tambet Matiisen <tambet(dot)matiisen(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Obscure behavior of ORDER BY
Date: 2011-03-23 21:09:06
Message-ID: AANLkTi=jPRd+36BXrzv09ybuBGFyc+qcEOkvDbfNi5f9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

this behave depends on your language rules. So this behave can be ok.

pavel=# select * from (values('.'),('@'),('.xxx'),(' xxxx')) x order by 1;
column1
─────────
.
@
.xxx
xxxx
(4 rows)

you can se so string with space on start is on end and this is
correct, because spaces and white chars are ignored.

Regards

Pavel Stehule.

2011/3/21 Tambet Matiisen <tambet(dot)matiisen(at)gmail(dot)com>:
> 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
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sree 2011-03-23 21:12:01 Re: converting big int to date
Previous Message Serdar Gül 2011-03-23 18:56:35 Re: xml2 support