Alter column data type in Amazon Redshift

前端 未结 9 1011
攒了一身酷
攒了一身酷 2020-12-12 20:45

How to alter column data type in Amazon Redshift database?

I am not able to alter the column data type in Redshift; is there any way to modify the data type in Amazo

9条回答
  •  天命终不由人
    2020-12-12 21:42

    UNLOAD and COPY with table rename strategy should be the most efficient way to do this operation if retaining the table structure(row order) is important.

    Here is an example adding to this answer.

    BEGIN TRANSACTION;
    
    ALTER TABLE  RENAME TO _OLD;
    CREATE TABLE  (  );
    UNLOAD ('select * from _OLD') TO 's3://bucket/key/unload_' manifest;
    COPY  FROM 's3://bucket/key/unload_manifest'manifest;
    
    END TRANSACTION;
    

提交回复
热议问题