[postgis-users] isnumeric function
Alexandre Dube
adube at mapgears.com
Thu Jun 11 10:36:44 PDT 2009
Hi Michael,
In my case, checking for integers is enough.
Thanks a lot for your answer though,
Alexandre
Michael Toews wrote:
> "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
>
>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the postgis-users
mailing list