casting character varying to integer - order by numeric sort - Mailing list pgsql-sql

From Bryce W Nesbitt
Subject casting character varying to integer - order by numeric sort
Date
Msg-id 4356EC5D.4080706@obviously.com
Whole thread Raw
Responses Re: casting character varying to integer - order by numeric
Re: casting character varying to integer - order by numeric sort
List pgsql-sql
How can I force a character field to sort as a numeric field?
I've got something like this:

Postgres=> SELECT username,last_name                 FROM eg_member ORDER BY username;
----------+-----------0120     | Foley1        | Sullivan10       | Guest11       | User
(5 rows)

(I can't change the field type).  I tried: SELECT username,last_name FROM eg_member ORDER BY username::integer;

But postgres 7 rejects this with "ERROR:  cannot cast type character 
varying to integer".  Is there a way to force numeric sort order?  I 
tried a variety of functions, such as to_char() and convert() without 
any luck.  Thanks for your insight!



pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: NULL in IN clause
Next
From: Terry Fielder
Date:
Subject: Re: casting character varying to integer - order by numeric