Skip to content

Commit a874217

Browse files
kyleconroyclaude
andcommitted
Add IF EXISTS support for RENAME COLUMN in ALTER TABLE
RENAME COLUMN IF EXISTS was not being parsed correctly - the IF token was being treated as the column name. This fix adds proper IF EXISTS handling for RENAME COLUMN, similar to DROP COLUMN. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 37d572e commit a874217

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

parser/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5899,6 +5899,12 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
58995899
if p.currentIs(token.COLUMN) {
59005900
cmd.Type = ast.AlterRenameColumn
59015901
p.nextToken()
5902+
// Handle IF EXISTS
5903+
if p.currentIs(token.IF) {
5904+
p.nextToken()
5905+
p.expect(token.EXISTS)
5906+
cmd.IfExists = true
5907+
}
59025908
// Parse column name (can be dotted like n.x for nested columns)
59035909
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
59045910
cmd.ColumnName = p.parseDottedIdentifier()
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)