Skip to content

Commit 81b0b38

Browse files
kyleconroyclaude
andcommitted
Add GENERATED ALWAYS AS support for ALTER TABLE ALTER COLUMN
- Parse GENERATED ALWAYS AS SUSER_SID/SUSER_SNAME START/END - Map to UserIdStart, UserIdEnd, UserNameStart, UserNameEnd values - Fix AddMaskingFunction/DropMaskingFunction option names Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1b69175 commit 81b0b38

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

ast/alter_table_alter_column_statement.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type AlterTableAlterColumnStatement struct {
1313
Encryption *ColumnEncryptionDefinition
1414
MaskingFunction ScalarExpression
1515
Options []IndexOption
16+
GeneratedAlways string // UserIdStart, UserIdEnd, UserNameStart, UserNameEnd, etc.
1617
}
1718

1819
func (a *AlterTableAlterColumnStatement) node() {}

parser/marshal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,9 @@ func alterTableAlterColumnStatementToJSON(s *ast.AlterTableAlterColumnStatement)
976976
if s.MaskingFunction != nil {
977977
node["MaskingFunction"] = scalarExpressionToJSON(s.MaskingFunction)
978978
}
979+
if s.GeneratedAlways != "" {
980+
node["GeneratedAlways"] = s.GeneratedAlways
981+
}
979982
if len(s.Options) > 0 {
980983
opts := make([]jsonNode, len(s.Options))
981984
for i, opt := range s.Options {

parser/parse_ddl.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,7 +5073,7 @@ func (p *Parser) parseAlterTableAlterColumnStatement(tableName *ast.SchemaObject
50735073
stmt.AlterTableAlterColumnOption = "AddHidden"
50745074
p.nextToken()
50755075
} else if nextLit == "MASKED" {
5076-
stmt.AlterTableAlterColumnOption = "AddMasked"
5076+
stmt.AlterTableAlterColumnOption = "AddMaskingFunction"
50775077
stmt.IsMasked = true
50785078
p.nextToken()
50795079
// Parse optional WITH (FUNCTION = '...')
@@ -5135,7 +5135,7 @@ func (p *Parser) parseAlterTableAlterColumnStatement(tableName *ast.SchemaObject
51355135
stmt.AlterTableAlterColumnOption = "DropHidden"
51365136
p.nextToken()
51375137
} else if nextLit == "MASKED" {
5138-
stmt.AlterTableAlterColumnOption = "DropMasked"
5138+
stmt.AlterTableAlterColumnOption = "DropMaskingFunction"
51395139
p.nextToken()
51405140
} else if nextLit == "NOT" {
51415141
p.nextToken() // consume NOT
@@ -5247,6 +5247,35 @@ func (p *Parser) parseAlterTableAlterColumnStatement(tableName *ast.SchemaObject
52475247
p.nextToken() // consume )
52485248
}
52495249
}
5250+
} else if upperLit == "GENERATED" {
5251+
p.nextToken() // consume GENERATED
5252+
if strings.ToUpper(p.curTok.Literal) == "ALWAYS" {
5253+
p.nextToken() // consume ALWAYS
5254+
}
5255+
if strings.ToUpper(p.curTok.Literal) == "AS" {
5256+
p.nextToken() // consume AS
5257+
}
5258+
// Parse the generated type: SUSER_SID, SUSER_SNAME, etc.
5259+
genType := strings.ToUpper(p.curTok.Literal)
5260+
p.nextToken()
5261+
// Parse START or END
5262+
startEnd := strings.ToUpper(p.curTok.Literal)
5263+
p.nextToken()
5264+
// Map to expected values
5265+
switch genType {
5266+
case "SUSER_SID":
5267+
if startEnd == "START" {
5268+
stmt.GeneratedAlways = "UserIdStart"
5269+
} else if startEnd == "END" {
5270+
stmt.GeneratedAlways = "UserIdEnd"
5271+
}
5272+
case "SUSER_SNAME":
5273+
if startEnd == "START" {
5274+
stmt.GeneratedAlways = "UserNameStart"
5275+
} else if startEnd == "END" {
5276+
stmt.GeneratedAlways = "UserNameEnd"
5277+
}
5278+
}
52505279
} else {
52515280
break
52525281
}
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)