Re: Seemingly inconsistent ORDER BY behavior - Mailing list pgsql-general

From rob stone
Subject Re: Seemingly inconsistent ORDER BY behavior
Date
Msg-id 1376510261.4764.21.camel@roblaptop.virtua.com.br
Whole thread Raw
In response to Seemingly inconsistent ORDER BY behavior  (Richard Hipp <drh@sqlite.org>)
List 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.



pgsql-general by date:

Previous
From: Richard Hipp
Date:
Subject: Re: Seemingly inconsistent ORDER BY behavior
Next
From: Tom Lane
Date:
Subject: Re: Seemingly inconsistent ORDER BY behavior