(redshift): Cannot add distkey to existing table #26733
Labels
@aws-cdk/aws-redshift
Related to Amazon Redshift
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p1
Describe the bug
Adding
distKey=true
to a column where the table previously had no distribution key fails to deploy because it tries to create the table.The diff:
The error:
Expected Behavior
CDK should add a distribution key to the table.
Current Behavior
CDK tries to create the table from scratch.
Reproduction Steps
It's unfortunately difficult for me to create a runnable snippet due to the amount of proprietary code used to generate it, but I've been able to reproduce the error with various tables in our system. The basic steps are:
.distKey(true)
for any single columnAs best as I can figure it, our code does something like this:
Possible Solution
The current code issues a
CREATE TABLE
statement if the table either has no distkey and we're adding one, or had a distkey and we're removing it:The problem here is that the resulting query tries to create a new table with the same name, which Redshift will reject because the table already exists.
Redshift supports adding and removing distribution keys on existing tables (see docs here) so we should take advantage of that. I believe the following will work:
Additional Information/Context
No response
CDK CLI Version
2.88.0
Framework Version
2.17.184
Node.js Version
20.5.1
OS
MacOS 13.5
Language
Java
Language Version
JDK 17
Other information
No response
The text was updated successfully, but these errors were encountered: