0 Replies - 4110 Views - Last Post: 02 September 2012 - 04:36 PM Rate Topic: -----

#1 Momentum   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 18-October 09

[PL/pgsql] Convert character varying to an integer

Posted 02 September 2012 - 04:36 PM


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

CREATE OR REPLACE FUNCTION "convToInt"(valuearg character varying)
  RETURNS integer AS

result int;

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

RETURN result;

  COST 100;
ALTER FUNCTION "convToInt"(character varying)
  OWNER TO postgres;

Is This A Good Question/Topic? 0
  • +

Page 1 of 1