Skip to content

Commit c0fff9f

Browse files
authored
Merge pull request #54 from PostHog/fix/alter-table-noops-ducklake
Make ALTER TABLE SET/DROP NOT NULL and DEFAULT no-ops for DuckLake
2 parents 306df91 + 9b6d607 commit c0fff9f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

transpiler/transform/ddl.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ func (t *DDLTransform) Transform(tree *pg_query.ParseResult, result *Result) (bo
8585

8686
case *pg_query.Node_AlterTableStmt:
8787
if n.AlterTableStmt != nil {
88-
// Check for ADD CONSTRAINT commands
88+
// Check for unsupported ALTER TABLE commands (constraints, NOT NULL, DEFAULT, etc.)
8989
for _, cmd := range n.AlterTableStmt.Cmds {
9090
if alterCmd := cmd.GetAlterTableCmd(); alterCmd != nil {
91-
// Check if this is adding a constraint
92-
if t.isConstraintCommand(alterCmd) {
91+
if t.isUnsupportedAlterCommand(alterCmd) {
9392
result.IsNoOp = true
9493
result.NoOpTag = "ALTER TABLE"
9594
return true, nil
@@ -301,11 +300,20 @@ func (t *DDLTransform) isUnsupportedDefault(expr *pg_query.Node) bool {
301300
return true
302301
}
303302

304-
// isConstraintCommand checks if an ALTER TABLE command is adding a constraint
305-
func (t *DDLTransform) isConstraintCommand(cmd *pg_query.AlterTableCmd) bool {
303+
// isUnsupportedAlterCommand checks if an ALTER TABLE command is unsupported by DuckLake
304+
func (t *DDLTransform) isUnsupportedAlterCommand(cmd *pg_query.AlterTableCmd) bool {
306305
switch cmd.Subtype {
306+
// Constraint commands
307307
case pg_query.AlterTableType_AT_AddConstraint,
308-
pg_query.AlterTableType_AT_ValidateConstraint:
308+
pg_query.AlterTableType_AT_ValidateConstraint,
309+
pg_query.AlterTableType_AT_DropConstraint:
310+
return true
311+
// NOT NULL commands - DuckLake doesn't handle these well
312+
case pg_query.AlterTableType_AT_SetNotNull,
313+
pg_query.AlterTableType_AT_DropNotNull:
314+
return true
315+
// DEFAULT commands - DuckLake has limited support
316+
case pg_query.AlterTableType_AT_ColumnDefault:
309317
return true
310318
}
311319
return false

transpiler/transpiler_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ func TestTranspile_DDL_NoOps(t *testing.T) {
333333
{"VACUUM", "VACUUM users", "VACUUM"},
334334
{"GRANT", "GRANT SELECT ON users TO public", "GRANT"},
335335
{"REVOKE", "REVOKE SELECT ON users FROM public", "REVOKE"},
336+
{"ALTER TABLE ADD CONSTRAINT", "ALTER TABLE users ADD CONSTRAINT pk_users PRIMARY KEY (id)", "ALTER TABLE"},
337+
{"ALTER TABLE SET NOT NULL", "ALTER TABLE users ALTER COLUMN name SET NOT NULL", "ALTER TABLE"},
338+
{"ALTER TABLE DROP NOT NULL", "ALTER TABLE users ALTER COLUMN name DROP NOT NULL", "ALTER TABLE"},
339+
{"ALTER TABLE SET DEFAULT", "ALTER TABLE users ALTER COLUMN status SET DEFAULT 'active'", "ALTER TABLE"},
340+
{"ALTER TABLE DROP DEFAULT", "ALTER TABLE users ALTER COLUMN status DROP DEFAULT", "ALTER TABLE"},
336341
}
337342

338343
tr := New(Config{DuckLakeMode: true})

0 commit comments

Comments
 (0)