Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: invalid input syntax for type numeric: "" (postgresql)

Tags:

sql

postgresql

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.

like image 259
Glenn G. Avatar asked Jan 16 '26 19:01

Glenn G.


1 Answers

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: ""
like image 55
Lukasz Szozda Avatar answered Jan 19 '26 18:01

Lukasz Szozda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!