pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #12603: Results Ordering not correct
3+ messages / 3 participants
[nested] [flat]

* BUG #12603: Results Ordering not correct
@ 2015-01-19 23:58 aruggiero@codarex.com
  2015-01-20 17:11 ` Re: BUG #12603: Results Ordering not correct Guillaume Lelarge <guillaume@lelarge.info>
  0 siblings, 1 reply; 3+ messages in thread

From: aruggiero@codarex.com @ 2015-01-19 23:58 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      12603
Logged by:          Antonio Ruggiero
Email address:      aruggiero@codarex.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 */




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #12603: Results Ordering not correct
  2015-01-19 23:58 BUG #12603: Results Ordering not correct aruggiero@codarex.com
@ 2015-01-20 17:11 ` Guillaume Lelarge <guillaume@lelarge.info>
  2015-01-20 17:27   ` Re: BUG #12603: Results Ordering not correct David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Guillaume Lelarge @ 2015-01-20 17:11 UTC (permalink / raw)
  To: aruggiero@codarex.com; +Cc: pgsql-bugs

Le 20 janv. 2015 17:21, <aruggiero@codarex.com> a écrit :
>
> The following bug has been logged on the website:
>
> Bug reference:      12603
> Logged by:          Antonio Ruggiero
> Email address:      aruggiero@codarex.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.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #12603: Results Ordering not correct
  2015-01-19 23:58 BUG #12603: Results Ordering not correct aruggiero@codarex.com
  2015-01-20 17:11 ` Re: BUG #12603: Results Ordering not correct Guillaume Lelarge <guillaume@lelarge.info>
@ 2015-01-20 17:27   ` David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David G Johnston @ 2015-01-20 17:27 UTC (permalink / raw)
  To: pgsql-bugs

Guillaume Lelarge-3 wrote
>> SELECT DISTINCT businessunit AS bu_id,
>> '('||businessunit::TEXT||')'||businessunitname as businessunit FROM
> bug_test
>> ORDER BY businessunit;
> 
> It is text. You renamed the second column businessunit.

To be more specific, the ORDER BY chooses an output column name before an
input column name.

http://www.postgresql.org/docs/9.1/static/sql-select.html

"Each expression can be the name or ordinal number of an output column
(SELECT list item), or it can be an arbitrary expression formed from
input-column values."

David J.



--
View this message in context: http://postgresql.nabble.com/BUG-12603-Results-Ordering-not-correct-tp5834749p5834765.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2015-01-20 17:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19 23:58 BUG #12603: Results Ordering not correct aruggiero@codarex.com
2015-01-20 17:11 ` Guillaume Lelarge <guillaume@lelarge.info>
2015-01-20 17:27   ` David G Johnston <david.g.johnston@gmail.com>

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