Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ func (s *SettingExpr) End() token.Position { return s.Position }
type InsertQuery struct {
Position token.Position `json:"-"`
Database string `json:"database,omitempty"`
Table string `json:"table"`
Table string `json:"table,omitempty"`
Function *FunctionCall `json:"function,omitempty"` // For INSERT INTO FUNCTION syntax
Columns []*Identifier `json:"columns,omitempty"`
Select Statement `json:"select,omitempty"`
Format *Identifier `json:"format,omitempty"`
Expand Down
6 changes: 5 additions & 1 deletion lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (l *Lexer) NextToken() Item {
return Item{Token: token.PERCENT, Value: "%", Pos: pos}
case '=':
l.readChar()
if l.ch == '=' {
l.readChar()
return Item{Token: token.EQ, Value: "==", Pos: pos}
}
return Item{Token: token.EQ, Value: "=", Pos: pos}
case '!':
if l.peekChar() == '=' {
Expand Down Expand Up @@ -407,7 +411,7 @@ func isIdentStart(ch rune) bool {
}

func isIdentChar(ch rune) bool {
return ch == '_' || unicode.IsLetter(ch) || unicode.IsDigit(ch)
return ch == '_' || ch == '$' || unicode.IsLetter(ch) || unicode.IsDigit(ch)
}

// Tokenize returns all tokens from the reader.
Expand Down
7 changes: 4 additions & 3 deletions parser/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *Parser) precedence(tok token.Token) int {
return CONCAT_PREC
case token.PLUS, token.MINUS:
return ADD_PREC
case token.ASTERISK, token.SLASH, token.PERCENT:
case token.ASTERISK, token.SLASH, token.PERCENT, token.DIV, token.MOD:
return MUL_PREC
case token.LPAREN, token.LBRACKET:
return CALL
Expand Down Expand Up @@ -173,7 +173,7 @@ func (p *Parser) parseInfixExpression(left ast.Expression) ast.Expression {
switch p.current.Token {
case token.PLUS, token.MINUS, token.ASTERISK, token.SLASH, token.PERCENT,
token.EQ, token.NEQ, token.LT, token.GT, token.LTE, token.GTE,
token.AND, token.OR, token.CONCAT:
token.AND, token.OR, token.CONCAT, token.DIV, token.MOD:
return p.parseBinaryExpression(left)
case token.NULL_SAFE_EQ:
return p.parseBinaryExpression(left)
Expand Down Expand Up @@ -1104,8 +1104,9 @@ func (p *Parser) parseDotAccess(left ast.Expression) ast.Expression {
func (p *Parser) parseAlias(left ast.Expression) ast.Expression {
p.nextToken() // skip AS

// Alias can be an identifier or a keyword (ClickHouse allows keywords as aliases)
alias := ""
if p.currentIs(token.IDENT) {
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
alias = p.current.Value
p.nextToken()
}
Expand Down
Loading