Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: partial support ALTER COLUMN TYPE (#2089)

rebelice2262c02069ea
diff --git a/plugin/parser/ast/alter_column_type_stmt.go b/plugin/parser/ast/alter_column_type_stmt.go
new file mode 100644
index 0000000000..b6522fc1a9
--- /dev/null
+++ b/plugin/parser/ast/alter_column_type_stmt.go
@@ -0,0 +1,9 @@
+package ast
+
+// AlterColumnTypeStmt is the struct for alter column type statement.
+type AlterColumnTypeStmt struct {
+ node
+
+ Table *TableDef
+ ColumnName string
+}
diff --git a/plugin/parser/engine/pg/convert.go b/plugin/parser/engine/pg/convert.go
index 8a0aa4c928..318f624e8a 100644
--- a/plugin/parser/engine/pg/convert.go
+++ b/plugin/parser/engine/pg/convert.go
@@ -87,6 +87,13 @@ func convert(node *pgquery.Node, text string) (res ast.Node, err error) {
}
alterTable.AlterItemList = append(alterTable.AlterItemList, dropNotNull)
+ case pgquery.AlterTableType_AT_AlterColumnType:
+ alterColumType := &ast.AlterColumnTypeStmt{
+ Table: alterTable.Table,
+ ColumnName: alterCmd.Name,
+ }
+
+ alterTable.AlterItemList = append(alterTable.AlterItemList, alterColumType)
}
}
}
diff --git a/plugin/parser/engine/pg/convert_test.go b/plugin/parser/engine/pg/convert_test.go
index 0b66ef63cf..8278c2b31f 100644
--- a/plugin/parser/engine/pg/convert_test.go
+++ b/plugin/parser/engine/pg/convert_test.go
@@ -1219,3 +1219,33 @@ func TestSetSchemaStmt(t *testing.T) {
runTests(t, tests)
}
+
+func TestAlterColumnType(t *testing.T) {
+ tests := []testData{
+ {
+ stmt: "ALTER TABLE tech_book ALTER COLUMN a TYPE string",
+ want: []ast.Node{
+ &ast.AlterTableStmt{
+ Table: &ast.TableDef{
+ Type: ast.TableTypeBaseTable,
+ Name: "tech_book",
+ },
+ AlterItemList: []ast.Node{
+ &ast.AlterColumnTypeStmt{
+ Table: &ast.TableDef{
+ Type: ast.TableTypeBaseTable,
+ Name: "tech_book",
+ },
+ ColumnName: "a",
+ },
+ },
+ },
+ },
+ textList: []string{
+ "ALTER TABLE tech_book ALTER COLUMN a TYPE string",
+ },
+ },
+ }
+
+ runTests(t, tests)
+}