Skip to content

Cannot parse COUNT(DISTINCT ...) #52

Description

@kendru

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions