Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql change varchar to integer

Tags:

sql

postgresql

I want to convert column type from varchar to integer in postgresql

ALTER TABLE billdetail ALTER COLUMN  masterid TYPE integer;

gives

[Err] ERROR:  column "masterid" cannot be cast automatically to type integer
HINT:  You might need to specify "USING masterid::integer".

while

   ALTER TABLE billdetail USING masterid::integer;

gives

[Err] ERROR:  syntax error at or near "USING"
LINE 1: ALTER TABLE billdetail USING masterid::integer;

How can I fix this problem?

like image 261
tee Avatar asked Apr 09 '26 02:04

tee


1 Answers

Try,

ALTER TABLE billdetail 
        ALTER COLUMN masterid TYPE INT USING masterid::integer;

You forgot to alter the column.

like image 83
Sachi Tekina Avatar answered Apr 10 '26 18:04

Sachi Tekina



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!