更改 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
)