Skip to content

Commit 050d0b2

Browse files
kyleconroyclaude
andcommitted
Allow NOT NULL constraint after DEFAULT expression
ClickHouse allows both orderings: - col Type NOT NULL DEFAULT expr - col Type DEFAULT expr NOT NULL Add second NOT NULL check after parsing DEFAULT/MATERIALIZED/ALIAS. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent befdafd commit 050d0b2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

parser/parser.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,6 +4366,21 @@ func (p *Parser) parseColumnDeclaration() *ast.ColumnDeclaration {
43664366
}
43674367
}
43684368

4369+
// Handle NOT NULL / NULL after DEFAULT (ClickHouse allows DEFAULT expr NOT NULL)
4370+
if p.currentIs(token.NOT) {
4371+
p.nextToken()
4372+
if p.currentIs(token.NULL) {
4373+
notNull := false
4374+
col.Nullable = &notNull
4375+
p.nextToken()
4376+
}
4377+
} else if p.currentIs(token.NULL) && col.Nullable == nil {
4378+
// NULL is explicit nullable (default)
4379+
nullable := true
4380+
col.Nullable = &nullable
4381+
p.nextToken()
4382+
}
4383+
43694384
// Parse CODEC
43704385
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "CODEC" {
43714386
p.nextToken()
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)