Skip to content

Allow using TRUNCATE instead of DROP TABLE when overwriting #671

Closed
@jaklan

Description

@jaklan

Is your idea related to a problem? Please describe.

When using awswrangler.redshift.to_sql with mode='overwrite', the following code is executed:

https://github.com/awslabs/aws-data-wrangler/blob/4d74d702474bf6209633a4b6285855fdd689eb0b/awswrangler/redshift.py#L228-L229

The approach fails if you have any views on top of the table.

redshift_connector.error.ProgrammingError: {'S': 'ERROR', 'C': '2BP01', 'M': 'cannot drop table some_schema.some_table
because other objects depend on it', 'H': 'Use DROP ... CASCADE to drop the dependent objects too.', 'F': '/home/ec2-
user/padb/src/pg/src/backend/catalog/dependency_v2.c', 'L': '677', 'R': 'reportDependentObjects'}

Describe the solution you'd like

  • overwrite mode should just truncate the table instead of dropping it
  • additional parameter for to_sql method should be provided, e.g. overwrite_method = "drop" | "truncate" | "cascade"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions