@@ -23,6 +23,7 @@ import (
2323 goerrors "github.com/ajitpratap0/GoSQLX/pkg/errors"
2424 "github.com/ajitpratap0/GoSQLX/pkg/models"
2525 "github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
26+ "github.com/ajitpratap0/GoSQLX/pkg/sql/keywords"
2627)
2728
2829// parseColumnName parses a column name in DDL context, accepting reserved keywords
@@ -92,6 +93,27 @@ func (p *Parser) parseColumnDef() (*ast.ColumnDef, error) {
9293 Type : dataTypeStr ,
9394 }
9495
96+ // ClickHouse column options that may appear between the type and the
97+ // standard constraint list: CODEC(...), DEFAULT expr, MATERIALIZED expr,
98+ // ALIAS expr, EPHEMERAL expr, TTL expr. Consume permissively; they are
99+ // appended to the type string for now so formatters can round-trip, and
100+ // not yet modeled on the AST.
101+ if p .dialect == string (keywords .DialectClickHouse ) {
102+ for {
103+ upper := strings .ToUpper (p .currentToken .Token .Value )
104+ if upper == "CODEC" && p .peekToken ().Token .Type == models .TokenTypeLParen {
105+ p .advance () // CODEC
106+ args , err := p .parseTypeArgsString ()
107+ if err != nil {
108+ return nil , err
109+ }
110+ colDef .Type += " CODEC" + args
111+ continue
112+ }
113+ break
114+ }
115+ }
116+
95117 // Parse column constraints
96118 for {
97119 constraint , ok , err := p .parseColumnConstraint ()
0 commit comments