Re: BUG #12603: Results Ordering not correct

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: aruggiero(at)codarex(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12603: Results Ordering not correct
Date: 2015-01-20 17:11:58
Message-ID: CAECtzeUhERY-tQLtCKmM39Pwy4wmcFckA0wySYuLTuU=e3nOTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Le 20 janv. 2015 17:21, <aruggiero(at)codarex(dot)com> a écrit :
>
> The following bug has been logged on the website:
>
> Bug reference: 12603
> Logged by: Antonio Ruggiero
> Email address: aruggiero(at)codarex(dot)com
> PostgreSQL version: 9.2.9
> Operating system: Windows 7 SP1
> Description:
>
> Summary: A field is Integer but results ordered as if it is text.
>
>
> /* START */
> DROP TABLE IF EXISTS bug_test;
> create table Bug_test (businessunit integer, businessunitname character
> varying(15));
>
> INSERT INTO bug_test VALUES (10,'North');
> INSERT INTO bug_test VALUES (20,'NorthEast');
> INSERT INTO bug_test VALUES (100,'East');
> INSERT INTO bug_test VALUES (110,'SouthEast');
> INSERT INTO bug_test VALUES (2000,'South');
> INSERT INTO bug_test VALUES (2100,'SouthWest');
> INSERT INTO bug_test VALUES (10000,'West');
> INSERT INTO bug_test VALUES (10100,'NorthWest');
>
>
> SELECT DISTINCT businessunit AS bu_id,
> '('||businessunit::TEXT||')'||businessunitname as businessunit FROM
bug_test
> ORDER BY businessunit;
> /* Output */
> /* --Notice results ordered as if businessunit is TEXT--
> bu_id, businessunit
> integer, text
> 10;'(10)North'
> 100;'(100)East'
> 10000;'(10000)West'
> 10100;'(10100)NorthWest'
> 110;'(110)SouthEast'
> 20;'(20)NorthEast'
> 2000;'(2000)South'
> 2100;'(2100)SouthWest'
> */
>
> SELECT DISTINCT businessunit AS bu_id,
> '('||businessunit::TEXT||')'||businessunitname as businessunit FROM
bug_test
> ORDER BY 1;
> /* Output */
> /* --Notice results ordered as if businessunit is INTEGER--
> bu_id, businessunit
> integer, text
> 10;'(10)North'
> 20;'(20)NorthEast'
> 100;'(100)East'
> 110;'(110)SouthEast'
> 2000;'(2000)South'
> 2100;'(2100)SouthWest'
> 10000;'(10000)West'
> 10100;'(10100)NorthWest'
> */
>
> DROP TABLE IF EXISTS bug_test;
>
> /* END */
>

It is text. You renamed the second column businessunit.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G Johnston 2015-01-20 17:27:11 Re: BUG #12603: Results Ordering not correct
Previous Message Pedro Gimeno 2015-01-20 05:57:46 Re: BUG #12589: Poor randomness from random() with some seeds; poor resolution