Thread: Query

Query

From
Eduardo Vázquez Rodríguez
Date:
Hi I have a field which vaules are numbers.

numbers
------
2
3
4
1
5
7
8
10
1
13
6
7
18


When I run a query asking for the field numbers sorted which look
something like this
SELECT numbers FROM TABLE
ORDER BY 1 ASC

And I get something like this
1
10
13
18
2
3
4, etc

Instead of I was expecting

1
2
3
etc
10
13
18


How can I fix it

Thanks in advanced

Re: Query

From
Eduardo Vázquez Rodríguez
Date:
Thanks!!!

I get the results that I wanted

vhikida@inreach.com wrote:

> Try something like
>
> SELECT TO_NUMBER(numbers,'99999')
>   FROM table
>  ORDER BY 1
>
> or
>
> SELECT numbers
>   FROM table
>  ORDER BY TO_NUMBER(numbers,'99999')
>
> You will have a problem if one of the values in the numbers column is not
> a number.
>
>
> See http://www.postgresql.org/docs/current/static/functions-formatting.html
> for more information on "TO_NUMBER".
>
>
>
>>Hi I have a field which vaules are numbers.
>>
>>numbers
>>------
>>2
>>3
>>4
>>1
>>5
>>7
>>8
>>10
>>1
>>13
>>6
>>7
>>18
>>
>>
>>When I run a query asking for the field numbers sorted which look
>>something like this
>>SELECT numbers FROM TABLE
>>ORDER BY 1 ASC
>>
>>And I get something like this
>>1
>>10
>>13
>>18
>>2
>>3
>>4, etc
>>
>>Instead of I was expecting
>>
>>1
>>2
>>3
>>etc
>>10
>>13
>>18
>>
>>
>>How can I fix it
>>
>>Thanks in advanced
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 3: if posting/reading through Usenet, please send an appropriate
>>      subscribe-nomail command to majordomo@postgresql.org so that your
>>      message can get through to the mailing list cleanly
>>
>
>
>

--
Eduardo Vázquez Rodríguez <evazquez@insys-corp.com.mx>
Consultoría Implantación
Tel. 5322 5200