Re: [SQL] casting character varying to integer - order by numeric

2005-10-20 Thread Bryce Nesbitt (mailing list account)
Cool, thanks. PostgreSQL 7.4.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20) Richard Huxton wrote: SELECT version(); ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster

Re: [SQL] casting character varying to integer - order by numeric

2005-10-20 Thread Richard Huxton
Bryce Nesbitt (mailing list account) wrote: Tom Lane wrote: As a general rule, you need to be more specific than that about which version you are working with ;-) Oooh, I'd be so happy to. But I don't know. Yes, I don't know. I know which version of "psql" is installed on my local machin

Re: [SQL] casting character varying to integer - order by numeric

2005-10-20 Thread Bryce Nesbitt (mailing list account)
Tom Lane wrote: But postgres 7 rejects this with "ERROR: cannot cast type character varying to integer". As a general rule, you need to be more specific than that about which version you are working with ;-) You may find that username::text::integer will work, depending on

Re: [SQL] casting character varying to integer - order by numeric sort

2005-10-19 Thread Tom Lane
Bryce W Nesbitt <[EMAIL PROTECTED]> writes: > 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". As a general rule, you need to be more specific than that about which version you

Re: [SQL] casting character varying to integer - order by numeric

2005-10-19 Thread Terry Fielder
Check out the function to_number() In particular here's an example... If a field named section is text containing numbers: ORDER BY to_number(t.section, text()) If the field can also contain non-numerals such as 3a, 3b, and you want 3a to show first then do this: ORDER BY to_number(t.s

[SQL] casting character varying to integer - order by numeric sort

2005-10-19 Thread Bryce W Nesbitt
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 | Foley 1| Sullivan 10 | Guest 11 | User (5 rows) (I can't chang