Re: Isnumeric function?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Theo Galanakis <Theo(dot)Galanakis(at)lonelyplanet(dot)com(dot)au>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Isnumeric function?
Date: 2004-09-08 18:11:51
Message-ID: 1094667111.2014.98.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 2004-09-08 at 18:48, Josh Berkus wrote:
> Theo, Oliver,
>
> > Any reason why you don't like ~ '^([0-9]?)+\.?[0-9]*$' ?
>
> Yes, because it also matches "." , which is not a valid numeric value.
>
> > ~ '^([0-9]+|[0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+)$'
>
> Ah, the brute force approach ;-)

Nothing like using a nice big hammer!

> Actually, the above could be written:
>
> ~ '^([0-9]+)|([0-9]*\\.[0-9]+)$'

But that doesn't allow a trailing decimal point.

>
> ... though that still seems inelegant to me. Is there a regex expert in the
> house?

All the elegant approaches I can think of match the empty string. There
must be at least one digit and 0 or 1 decimal point with no other
characters permitted. If you use this as a constraint, you could make
it elegant and combine it with another constraint to exclude '' and '.'.
--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Put on the whole armor of God, that ye may be able to
stand against the wiles of the devil."
Ephesians 6:11

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kemin Zhou 2004-09-08 21:11:38 aggregate function stddev
Previous Message Josh Berkus 2004-09-08 17:48:01 Re: Isnumeric function?