pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
sort text field numerically
2+ messages / 2 participants
[nested] [flat]

* sort text field numerically
@ 2002-05-14 12:23  Frank Morton <fmorton@base2inc.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Frank Morton @ 2002-05-14 12:23 UTC (permalink / raw)
  To: pgsql-sql

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.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: sort text field numerically
@ 2002-05-14 12:43  Joel Burton <joel@joelburton.com>
  parent: Frank Morton <fmorton@base2inc.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Joel Burton @ 2002-05-14 12:43 UTC (permalink / raw)
  To: Frank Morton <fmorton@base2inc.com>; pgsql-sql

> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org
> [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Frank Morton
> Sent: Tuesday, May 14, 2002 8:24 AM
> To: pgsql-sql@postgresql.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@joelburton.com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-05-14 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-14 12:23 sort text field numerically Frank Morton <fmorton@base2inc.com>
2002-05-14 12:43 ` Joel Burton <joel@joelburton.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox