JakeWheat/hssqlppp — Issue #4: Parsing (and may be more): COUNT(DISTINCT …) syntax is not supported
Author: portnov
Created: 2011-10-26 13:11:02+00:00
State: open

As far as I see, HsSqlPpp parser (and AST?) does not support COUNT(DISTINCT column_name) syntax at all. For example,

> parseQueryExpr "" "SELECT COUNT(DISTINCT column) FROM table"

Right (Select (Annotation {asrc = Just ("",1,1), atype = Nothing, errs = [],
stType = Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) Dupes
(SelectList (Annotation {asrc = Just ("",1,8), atype = Nothing, errs = [],
stType = Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) [SelExp
(Annotation {asrc = Just ("",1,8), atype = Nothing, errs = [], stType =
Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) (FunCall
(Annotation {asrc = Just ("",1,13), atype = Nothing, errs = [], stType =
Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) "count"
[Identifier (Annotation {asrc = Just ("",1,23), atype = Nothing, errs = [],
stType = Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) "column"])])
[Tref (Annotation {asrc = Just ("",1,31), atype = Nothing, errs = [], stType =
Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) (SQIdentifier
(Annotation {asrc = Just ("",1,31), atype = Nothing, errs = [], stType =
Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}) ["table"])
(NoAlias (Annotation {asrc = Just ("",1,31), atype = Nothing, errs = [],
stType = Nothing, catUpd = [], fnProt = Nothing, infType = Nothing}))] Nothing
[] Nothing [] Nothing Nothing)

The simplest (but hacky) way to fix this seems to add dummy Boolean argument to COUNT function in the AST. For example, COUNT(False, field) will mean COUNT(field) and COUNT(True, field) will mean COUNT(DISTINCT field). But maybe we need more generic support for such cases in AST?