From: | "Joel Burton" <joel(at)joelburton(dot)com> |
---|---|
To: | "Frank Morton" <fmorton(at)base2inc(dot)com>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: sort text field numerically |
Date: | 2002-05-14 12:43:19 |
Message-ID: | JGEPJNMCKODMDHGOBKDNOEBHCOAA.joel@joelburton.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> -----Original Message-----
> From: pgsql-sql-owner(at)postgresql(dot)org
> [mailto:pgsql-sql-owner(at)postgresql(dot)org]On Behalf Of Frank Morton
> Sent: Tuesday, May 14, 2002 8:24 AM
> To: pgsql-sql(at)postgresql(dot)org
> Subject: [SQL] sort text field numerically
>
>
> I have a table with a column called "weight" that
> is a text field, but in this case, contains float values,
> such as ".8" or "0.25". Might also be null.
>
> How can I sort them in numeric order instead of
> textual order? Thanks.
select * from floats_table order by text_float_field::float;
will work, as long as there are no non-float items in the table (if there
are, you could use an ORDER BY CASE ... to look for non-numeric characters
and sort these differently, and sort the rest by converting to floats as
::float)
HTH.
Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant
From | Date | Subject | |
---|---|---|---|
Next Message | Christoph Haller | 2002-05-14 13:58:23 | Re: order by <something wierd> |
Previous Message | Mathieu Arnold | 2002-05-14 12:28:57 | Re: order by <something wierd> |