Skip to content

Commit e29bfbb

Browse files
kyleconroyclaude
andcommitted
Add PERIOD FOR SYSTEM_TIME support in ALTER TABLE statements
- Handle ADD PERIOD FOR SYSTEM_TIME (start, end) in ALTER TABLE ADD - Handle DROP PERIOD FOR SYSTEM_TIME in ALTER TABLE DROP - Set TableElementType to "Period" for period elements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 66f3e1d commit e29bfbb

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

parser/parse_ddl.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,6 +5117,29 @@ func (p *Parser) parseAlterTableDropStatement(tableName *ast.SchemaObjectName) (
51175117
case p.curTok.Type == TokenIndex:
51185118
currentElementType = "Index"
51195119
p.nextToken()
5120+
case strings.ToUpper(p.curTok.Literal) == "PERIOD":
5121+
// DROP PERIOD FOR SYSTEM_TIME
5122+
currentElementType = "Period"
5123+
p.nextToken() // consume PERIOD
5124+
if strings.ToUpper(p.curTok.Literal) == "FOR" {
5125+
p.nextToken() // consume FOR
5126+
}
5127+
if strings.ToUpper(p.curTok.Literal) == "SYSTEM_TIME" {
5128+
p.nextToken() // consume SYSTEM_TIME
5129+
}
5130+
// Create the element with no name
5131+
element := &ast.AlterTableDropTableElement{
5132+
TableElementType: currentElementType,
5133+
IsIfExists: false,
5134+
}
5135+
stmt.AlterTableDropTableElements = append(stmt.AlterTableDropTableElements, element)
5136+
// Reset and continue
5137+
currentElementType = "NotSpecified"
5138+
if p.curTok.Type == TokenComma {
5139+
p.nextToken() // consume comma
5140+
continue
5141+
}
5142+
break
51205143
}
51215144

51225145
// Check for IF EXISTS
@@ -6579,6 +6602,32 @@ func (p *Parser) parseAlterTableAddStatement(tableName *ast.SchemaObjectName) (*
65796602
stmt.Definition.TableConstraints = append(stmt.Definition.TableConstraints, constraint)
65806603
}
65816604
}
6605+
} else if strings.ToUpper(p.curTok.Literal) == "PERIOD" {
6606+
// Parse PERIOD FOR SYSTEM_TIME (start, end)
6607+
p.nextToken() // consume PERIOD
6608+
if strings.ToUpper(p.curTok.Literal) == "FOR" {
6609+
p.nextToken() // consume FOR
6610+
}
6611+
if strings.ToUpper(p.curTok.Literal) == "SYSTEM_TIME" {
6612+
p.nextToken() // consume SYSTEM_TIME
6613+
}
6614+
// Parse (start_column, end_column)
6615+
var startCol, endCol *ast.Identifier
6616+
if p.curTok.Type == TokenLParen {
6617+
p.nextToken() // consume (
6618+
startCol = p.parseIdentifier()
6619+
if p.curTok.Type == TokenComma {
6620+
p.nextToken() // consume ,
6621+
}
6622+
endCol = p.parseIdentifier()
6623+
if p.curTok.Type == TokenRParen {
6624+
p.nextToken() // consume )
6625+
}
6626+
}
6627+
stmt.Definition.SystemTimePeriod = &ast.SystemTimePeriodDefinition{
6628+
StartTimeColumn: startCol,
6629+
EndTimeColumn: endCol,
6630+
}
65826631
} else {
65836632
// Parse column definition (column_name data_type ...)
65846633
colDef, err := p.parseColumnDefinition()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)