xsqlparser icon indicating copy to clipboard operation
xsqlparser copied to clipboard

Cannot parse COUNT(DISTINCT ...)

Open kendru opened this issue 3 years ago • 0 comments

The parser fails with an error when parsing a COUNT(DISTINCT ...) expression. It seems that the AST cannot represent this expression.

Example:

package main

import (
	"bytes"
	"log"

	"github.com/akito0107/xsqlparser"
	"github.com/akito0107/xsqlparser/dialect"
)

func main() {
	sql := "SELECT COUNT(DISTINCT id) FROM foo"
	parser, _ := xsqlparser.NewParser(bytes.NewBufferString(sql), &dialect.MySQLDialect{})
	_, err := parser.ParseStatement()
	if err != nil {
		log.Fatalln(err)
	}
}

Error:

2022/06/10 15:31:33 parseQueryBody failed: parseSelect failed: parseSelectList failed: ParseExpr failed: parsePrefix failed: parseFunction failed: expected RParen but &{Kind:SQLKeyword Value:id From:{Line:1 Col:23} To:{Line:1 Col:25}}
exit status 1

kendru avatar Jun 10 '22 21:06 kendru