Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ALTER TABLE support for DuckDB tables #652

Merged
merged 21 commits into from
Mar 11, 2025
Merged

Add ALTER TABLE support for DuckDB tables #652

merged 21 commits into from
Mar 11, 2025

Conversation

JelteF
Copy link
Collaborator

@JelteF JelteF commented Mar 7, 2025

Adds all ALTER TABLE commands that DuckDB can parse except for COLLATION changes and foreign keys. Not all of these ALTER commands are actually supported by DuckDB (e.g. adding CHECK constraints). But this starts to least forward those queries correctly to DuckDB, so once DuckDB supports it pg_duckdb will start to automatically support it as well.

Fixes #536
Fixes #537
Fixes #538
Fixes #539
Fixes #540
Fixes #541
Fixes #542

@JelteF JelteF requested a review from Y-- March 10, 2025 10:10
Copy link
Collaborator

@Y-- Y-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, especially given all the tests it seems we have a reasonable coverage. Main question is around the global state lifecycle?

@@ -181,6 +187,7 @@ DuckdbHandleDDL(PlannedStmt *pstmt, const char *query_string, ParamListInfo para
char *access_method = stmt->accessMethod ? stmt->accessMethod : default_table_access_method;
bool is_duckdb_table = strcmp(access_method, "duckdb") == 0;
if (is_duckdb_table) {
pgduckdb::top_level_duckdb_ddl_type = pgduckdb::DDLType::CREATE_TABLE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we assert that this is DDLType::NONE before updating it? (same everywhere we update it). Or we're confident this can never happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty confident it cannot happen, but I guess it's better safe than sorry. So now it throws an error in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the same below (L216?)

@JelteF JelteF requested a review from Y-- March 11, 2025 15:19
@JelteF JelteF enabled auto-merge (squash) March 11, 2025 15:23
@JelteF JelteF merged commit c4a86c2 into main Mar 11, 2025
5 checks passed
@JelteF JelteF deleted the motherduck-alter branch March 11, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants