If you want to change character to integer in postgresql use the following
1) Create a function
CREATE OR REPLACE FUNCTION otc_chartoint(chartoconvert character varying)
RETURNS integer AS
$BODY$
SELECT CASE WHEN trim($1) SIMILAR TO '[0-9]+'
THEN CAST(trim($1) AS integer)
ELSE NULL END;
$BODY$
LANGUAGE 'sql' IMMUTABLE STRICT;
2)Run this query
ALTER TABLE <Table Name> ALTER COLUMN <Column Name> TYPE integer USING otc_chartoint(<Column Name>);
No comments:
Post a Comment