3

I'm trying to alter the column data type in my postgresql table. The column name is _2010_10, type is text, and the value is 18.74 (in text format). I'm trying to change the text type to numeric. This is my input/output:

ALTER table cadata.pricetorentratio 
ALTER column _2010_10 type numeric USING (trim(_2010_10)::numeric);

ERROR: invalid input syntax for type numeric: ""

Not sure why I'm getting this error.

2 Answers 2

5

You could use NULLIF to handle blank string '':

ALTER table pricetorentratio 
ALTER column _2010_10 type numeric USING (NULLIF(trim(_2010_10),'')::numeric);

DBFiddle Demo


SELECT ''::numeric
-- invalid input syntax for type numeric: ""
Sign up to request clarification or add additional context in comments.

Comments

-1
ALTER TABLE `pricetorentratio` CHANGE `_2010_10` `_2010_10` FLOAT NULL DEFAULT NULL;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.