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
2 changes: 1 addition & 1 deletion parser/parser_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ func (p *Parser) parseOrderExpr(pos Pos) (*OrderExpr, error) {
var alias *Ident
if p.matchKeyword(KeywordAs) {
// It should be a subquery instead of an order by alias if the `AS` is followed by `SELECT` keyword.
if nextToken, err := p.lexer.peekToken(); err == nil && nextToken.ToString() == KeywordSelect {
if nextToken, err := p.lexer.peekToken(); err == nil && nextToken != nil && nextToken.ToString() == KeywordSelect {
return &OrderExpr{
OrderPos: pos,
Expr: columnExpr,
Expand Down
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ func TestParser_InvalidSyntax(t *testing.T) {
// ClickHouse rejects a set operator once SETTINGS is bound to a
// parenthesized group
"(SELECT 1) SETTINGS max_threads=1 UNION ALL SELECT 2",
// AS at the very end of an ORDER BY item leaves no token to check for SELECT
"SELECT * FROM t ORDER BY a AS",
}
for _, sql := range invalidSQLs {
parser := NewParser(sql)
Expand Down
Loading