我有一个包含以下数据的PostgreSQL数据表</ p>
id assignmentId folderId folderId_new
1 2274 5332
2 2274 5348
3 2274 5349
4 2274 5350
46 2277 5355
75 2275 5351
76 2275 5352
77 2275 5353
78 2275 5354
...
和列数据类型
id serial
assignmentId integer
folderId text
folderId_new integer
我想将folderId列的值保存到folderId_new列 我尝试过以下查询
update framethreshold set folderId_new = CAST (folderId AS integer)
update framethreshold set folderId_new = folderId::int
但会导致错误:
ERROR: invalid input syntax for integer: "" SQL state: 22P02
答案 0 :(得分:1)
好的,所以你可以写这个查询
update framethreshold set folderId_new = NULLIF(folderId, '')::int
希望这会奏效;)