AWS红移 - 添加IDENTITY列到现有的表AWS、IDENTITY

2023-09-11 11:46:50 作者:烈酒焚骨

在AWS红移,试图使用命令IDENTITY列添加到现有表时

  ALTER TABLE table_name的ADD列ID BIGINT IDENTITY(1,1);
 

我收到以下错误

  

错误:ALTER TABLE ADD COLUMN不支持类型IDENTITY列

这显然意味着,这根本是不红移不允许的。我是否需要删除并重新创建表?或者是有一些变通的解决方案得到这个红移做?

解决方案 亚马逊 re Invent 2020 AWS Identity 选择合适的IAM策略组合进行扩展

您必须添加身份表声明中的列。你以后就不能添加。

  

文档:       不能使用ALTER TABLE ADD COLUMN命令修改下表和列属性:

  UNIQUE

    首要的关键

    参考文献(外键)

    IDENTITY
 

In AWS Redshift, when attempting to add an IDENTITY column to an existing table using the command

ALTER TABLE table_name ADD COLUMN id bigint IDENTITY(1,1);

I get the following error

ERROR: ALTER TABLE ADD COLUMN does not support columns with type IDENTITY

Which obviously implies that this simply isn't allowed in Redshift. Will I need to drop and recreate the table? Or is there some workaround solution to get this done in Redshift?

解决方案

You must add IDENTITY column during table declaration. And you can't add it later.

Docs: You cannot use an ALTER TABLE ADD COLUMN command to modify the following table and column attributes:

    UNIQUE

    PRIMARY KEY

    REFERENCES (foreign key)

    IDENTITY