DerekStride / tree-sitter-sql

SQL grammar for tree-sitter
http://derek.stride.host/tree-sitter-sql/
MIT License
155 stars 52 forks source link

`ERROR` on `COUNT(DISTINCT tbl.field)` #154

Closed LeoniePhiline closed 1 year ago

LeoniePhiline commented 1 year ago

image

Tree-sitter syntax error for tbl and field in:

SELECT
  COUNT(DISTINCT `tbl`.`field`)
FROM
  whatever;
matthias-Q commented 1 year ago

I think this issue may be resolved when #150 is merged. The issue is that the term can be a field and there we have issue when the field is like scm.tbl.col.

Just to recap the tree here: invocation -> _select_expression -> term -> _expression -> field -> [schema: _alias_identifier.][table_alias: _alias_identifier.]identifier

_alias_identifier -> identifier -> `_idenfier`

I am a bit surprised that is does not work at the moment.

EDIT: Ah now I get it. The distinct is not registered correctly at all. It is interpreted as a field and the column afterwards as alias of that column

LeoniePhiline commented 1 year ago

Ah yes. I did not pay attention to DISTINCT, since it did not error out. My mistake in not pointing that out!

DISTINCT is indeed mis-identified as "field", "identifier":

image

matthias-Q commented 1 year ago

I am preparing a fix right now