Re: Seemingly inconsistent ORDER BY behavior

From: rob stone <floriparob(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Seemingly inconsistent ORDER BY behavior
Date: 2013-08-14 19:57:41
Message-ID: 1376510261.4764.21.camel@roblaptop.virtua.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2013-08-14 at 14:01 -0400, Richard Hipp wrote:
> CREATE TABLE t1(m VARCHAR(4));
> INSERT INTO t1 VALUES('az');
> INSERT INTO t1 VALUES('by');
> INSERT INTO t1 VALUES('cx');
>
> SELECT '1', substr(m,2) AS m
> FROM t1
> ORDER BY m;
>
> SELECT '2', substr(m,2) AS m
> FROM t1
> ORDER BY lower(m);

You cannot cast your ORDER BY column value.

Instead:-

SELECT '2', LOWER(substr(m,2)) AS m
FROM t1
ORDER BY m;

will have the desired effect.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-08-14 20:12:18 Re: Seemingly inconsistent ORDER BY behavior
Previous Message Richard Hipp 2013-08-14 19:50:15 Re: Seemingly inconsistent ORDER BY behavior