在AWS Redshift中,我想向已创建的表添加排序键。是否有任何命令可以添加列并将其用作排序键?
最佳答案
更新:
Amazon Redshift now enables users to add and change sort keys of existing Redshift tables without having to re-create the table. The new capability simplifies user experience in maintaining the optimal sort order in Redshift to achieve high performance as their query patterns evolve and do it without interrupting the access to the tables.
来源:https://aws.amazon.com/about-aws/whats-new/2019/11/amazon-redshift-supports-changing-table-sort-keys-dynamically/
目前,我认为这是不可能的(希望将来会改变)。过去,当我遇到这种情况时,我创建了一个新表并将数据从旧表复制到该表中。
来自http://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html:
ADD [ COLUMN ] column_name Adds a column with the specified name to the table. You can add only one column in each ALTER TABLE statement.
You cannot add a column that is the distribution key (DISTKEY) or a sort key (SORTKEY) of the table.
You cannot use an ALTER TABLE ADD COLUMN command to modify the following table and column attributes:
UNIQUE
PRIMARY KEY
REFERENCES (foreign key)
IDENTITY
The maximum column name length is 127 characters; longer names are truncated to 127 characters. The maximum number of columns you can define in a single table is 1,600.
关于amazon-redshift - 如何在AWS Redshift中向现有表添加排序键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17884203/