Re: Sorting by numerical order

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: peter_e(at)gmx(dot)net (Peter Eisentraut)
Cc: cool_screen_name90001(at)yahoo(dot)com (CSN), pgsql-general(at)postgresql(dot)org
Subject: Re: Sorting by numerical order
Date: 2004-03-14 22:59:45
Message-ID: 200403142259.i2EMxk1F007960@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> CSN wrote:
> > Is it possible to have items sorted like:
> >
> > abc 1
> > abc 2
> > abc 10
> > abc 20
>
> Cast them to a numeric type.

You can't cast a variable char type to a numeric, though apparently
you can cast text to numeric. (I'd be curious to know why one but not
the other.)

However, if I understood the original question, 'abc 1' and 'abc 20' are
contents of a single column, which might make separating out just the
numeric part tricky.

On a somewhat related subject, how difficult would it be to write an
'isnumeric' function as part of the source code as opposed to a user
function in pgsql or perl?

I have some data that is mostly numeric but not always so. I know from
other columns whether a particular row is supposed to contain a numeric
value or not, but the data is coming from a legacy environment
and isn't 100% reliable.

An 'isnumeric(column)' boolean function in a case statment would be
very helpful so that I can program around the bad data.

I'll probably write it in perl, but would making it part of the source
code provide significantly faster execution?
--
Mike Nolan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric B.Ridge 2004-03-14 23:06:38 Re: How reliable are the stats collector stats?
Previous Message Frank Finner 2004-03-14 22:06:53 Re: PostgeSQL problem (server crashed?)