change column datatype from array to integer

前端 未结 2 985
Happy的楠姐
Happy的楠姐 2021-01-29 14:39

I need to change the data type of a column from _float8 to int4

ALTER TABLE \"table\" ALTER COLUMN \"col\" SET DATA TYPE int4;

results in

2条回答
  •  旧巷少年郎
    2021-01-29 15:30

    The problem is that you have an array. To fix this, you need array operators:

    ALTER TABLE "table"
        ALTER COLUMN "col" SET DATA TYPE int4 USING (col[1]::integer);
    

    Here is a db<>fiddle.

提交回复
热议问题