[postgis-users] isnumeric function

Michael Toews mwtoews at sfu.ca
Wed Jun 10 10:11:25 PDT 2009


"Numeric" is an ambiguous qualifier. This really depends on what you define as numeric: integers or reals. Furthermore, if you have negatives, or exponential notation, etc. I'd investigate into regular expressions in general (and also http://www.postgresql.org/docs/current/static/functions-matching.html).

If you want a floating point (and integer) regexp function, try instead:

CREATE OR REPLACE FUNCTION isnumeric(text)
  RETURNS boolean AS $BODY$SELECT $1 ~ E'^[-+]?\\d*\\.?\\d+(?:[eE][-+]?\\d+)?$'$BODY$
  LANGUAGE 'sql' IMMUTABLE;

(note: [eE] tests for numbers like '4.3e-32'; also IMMUTABLE is used to increase performance on large queries)

-Mike

----- Original Message -----
From: "Alexandre Dube" <adube at mapgears.com>
To: "PostGIS Users Discussion" <postgis-users at postgis.refractions.net>
Sent: Wednesday, 10 June, 2009 08:21:56 GMT -08:00 US/Canada Pacific
Subject: Re: [postgis-users] isnumeric function

Hi,

  Still searching for a solution...  Any hint ?

Alexandre

Alexandre Dube wrote:
> Hi,
>
>  I'm looking for an isnumeric() function in postgresql.  I did a quick 
> research and only found this :
>
> http://archives.postgresql.org/pgsql-sql/2004-04/msg00336.php
>
>  Is there still no such function in postgresql ?
>


-- 
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list