postgresql将varchar改为integer

sc4hvdpw  于 5个月前  发布在  PostgreSQL
关注(0)|答案(2)|浏览(46)

我想在postgresql中将列类型从varchar转换为整型

ALTER TABLE billdetail ALTER COLUMN  masterid TYPE integer;

字符串

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


ALTER TABLE billdetail USING masterid::integer;


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


如何解决此问题?

unhi4e5o

unhi4e5o1#

试试看

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

字符串
你忘了改专栏了。

izj3ouym

izj3ouym2#

ALTER TABLE table_name ALTER COLUMN col_name TYPE INT USING col_name::integer;

字符串

相关问题