0

I am trying to make a database-level function Postgres (version 9.4) to check that a given variable is numeric.

Been messing around but can't figure this out easily and wondering if there is some built in function for htis...

Walker Farrow
  • 3,579
  • 7
  • 29
  • 51
  • Possible duplicate of [isnumeric() with PostgreSQL](http://stackoverflow.com/questions/16195986/isnumeric-with-postgresql) – mvp May 18 '16 at 21:17

1 Answers1

1

Try this one:

CREATE OR REPLACE FUNCTION  is_number(text) RETURNS  boolean AS $$
DECLARE x NUMERIC;
BEGIN
    x = $1::NUMERIC;
    RETURN TRUE;
EXCEPTION WHEN others THEN
    RETURN FALSE;
END;
$$ LANGUAGE plpgsql IMMUTABLE;

After googling, I've found duplicate

Community
  • 1
  • 1
Beri
  • 11,470
  • 4
  • 35
  • 57