Hi,

browsing the internet I found a few solutions. While trying out the solutions, I combined some the ideas and found the following code works.
But is it efficient and is it a trustful solution? Basically casting a numeric type to an integer

Code:
CREATE OR REPLACE FUNCTION "convToInt"(valuearg character varying)
  RETURNS integer AS
$BODY$DECLARE

result int;

BEGIN
EXECUTE 'SELECT to_number(quote_literal($1), quote_literal(99999999))' INTO result
USING valuearg;

RETURN result;


END$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION "convToInt"(character varying)
  OWNER TO postgres;