Skip to content

Commit c70d18b

Browse files
authored
Add support for RENAME TABLE and table synonyms (#165)
1 parent 4099da8 commit c70d18b

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

statement.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var (
9292
grantRe = regexp.MustCompile(`(?is)^GRANT\s.+$`)
9393
revokeRe = regexp.MustCompile(`(?is)^REVOKE\s.+$`)
9494
alterRe = regexp.MustCompile(`(?is)^ALTER\s.+$`)
95+
renameRe = regexp.MustCompile(`(?is)^RENAME\s.+$`)
9596
truncateTableRe = regexp.MustCompile(`(?is)^TRUNCATE\s+TABLE\s+(.+)$`)
9697
analyzeRe = regexp.MustCompile(`(?is)^ANALYZE$`)
9798

@@ -150,6 +151,8 @@ func BuildStatementWithComments(stripped, raw string) (Statement, error) {
150151
return &DdlStatement{Ddl: stripped}, nil
151152
case alterRe.MatchString(stripped):
152153
return &DdlStatement{Ddl: stripped}, nil
154+
case renameRe.MatchString(stripped):
155+
return &DdlStatement{Ddl: stripped}, nil
153156
case grantRe.MatchString(stripped):
154157
return &DdlStatement{Ddl: stripped}, nil
155158
case revokeRe.MatchString(stripped):

statement_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ func TestBuildStatement(t *testing.T) {
9191
input: "CREATE TABLE t1 (id INT64 NOT NULL) PRIMARY KEY (id)",
9292
want: &DdlStatement{Ddl: "CREATE TABLE t1 (id INT64 NOT NULL) PRIMARY KEY (id)"},
9393
},
94+
{
95+
desc: "RENAME TABLE statement",
96+
input: "RENAME TABLE t1 TO t2, t3 TO t4",
97+
want: &DdlStatement{Ddl: "RENAME TABLE t1 TO t2, t3 TO t4"},
98+
},
9499
{
95100
desc: "ALTER TABLE statement",
96101
input: "ALTER TABLE t1 ADD COLUMN name STRING(16) NOT NULL",

0 commit comments

Comments
 (0)