Re: order by int - Mailing list pgsql-novice

From Henshall, Stuart - WCP
Subject Re: order by int
Date
Msg-id E2870D8CE1CCD311BAF50008C71EDE8E01F74942@MAIL_EXCHANGE
Whole thread Raw
In response to order by int  ("Duncan Adams (DNS)" <duncan.adams@vcontractor.co.za>)
List pgsql-novice

It looks like you are ordering by text rather than a number.
If you need to convert text to a number it can be done like so:
cast('123' AS int4)
so for ordering the query might look like:
select * from tbl order by CAST(text_field AS int4);
hth,
- Stuart

> -----Original Message-----
> From: Duncan Adams (DNS) [mailto:duncan.adams@vcontractor.co.za]
> Sent: 26 July 2002 13:26
> To: pgsql-novice@postgresql.org
> Subject: [NOVICE] order by int
>
>
> Hi all

> quick question
>
> how does one get
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> instead of
> 1
> 10
> 11
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> when one does an order by <int>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>

pgsql-novice by date:

Previous
From: "Daniel L Banta"
Date:
Subject: initdb initialization problem
Next
From: "Duncan Adams (DNS)"
Date:
Subject: Re: order by int