更改 Amazon Redshift 中的列数据类型 [英] Alter column data type in Amazon Redshift

查看:43
本文介绍了更改 Amazon Redshift 中的列数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 Amazon Redshift 数据库中的列数据类型?

How to alter column data type in Amazon Redshift database?

我无法在 Redshift 中更改列数据类型;有没有办法修改 Amazon Redshift 中的数据类型?

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

推荐答案

ALTER TABLE 文档,您可以使用

ALTER TABLE table_name
{
    ALTER COLUMN column_name TYPE new_data_type 
}

对于其他列类型,我能想到的就是添加一个具有正确数据类型的新列,然后将旧列中的所有数据插入到新列中,最后删除旧列.

For other column types all I can think of is to add a new column with a correct datatype, then insert all data from old column to a new one, and finally drop the old column.

使用类似的代码:

ALTER TABLE t1 ADD COLUMN new_column ___correct_column_type___;
UPDATE t1 SET new_column = column;
ALTER TABLE t1 DROP COLUMN column;
ALTER TABLE t1 RENAME COLUMN new_column TO column;

将会有一个架构更改 - 新添加的列将在表中的最后一个(这可能是 COPY 语句的问题,请记住这一点 - 您可以使用 <代码>复制)

There will be a schema change - the newly added column will be last in a table (that may be a problem with COPY statement, keep that in mind - you can define a column order with COPY)

这篇关于更改 Amazon Redshift 中的列数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆