Zaid-Ajaj / Npgsql.FSharp.Analyzer

F# analyzer that provides embedded SQL syntax analysis, type-checking for parameters and result sets and nullable column detection when writing queries using Npgsql.FSharp.
MIT License
137 stars 9 forks source link

Question: why is DISTINCT ignored in the query AST #24

Open sebastian opened 3 years ago

sebastian commented 3 years ago

Your SQL parser parses the distinct keyword (when used in the context of a list of columns being selected), but does not retain it in the purposes of the AST.

As an example, take the following test where the query

SELECT DISTINCT username, user_id FROM users

is parsed into the following list of columns, losing the distinct keyword in the process:

[Expr.Ident "username"; Expr.Ident "user_id"]

Is this an artefact of your analyzer not needing the distinct keyword in order to do its type checking? In other words, is this a conscious omission?

Zaid-Ajaj commented 3 years ago

Hi @sebastian, so about the parser. It is really a very slimmed down version of SQL and not a full parser. This is because I only use the parser for some very specific cases when the database doesn't give me enough information (such as input parameter nullability). To circle back to your question:

Is this an artefact of your analyzer not needing the distinct keyword in order to do its type checking?

Yes

In other words, is this a conscious omission?

Yes and no. I just don't have any use case for the distinct keyword because using it doesn't change the static types of the query. However, if you need it for some project you are working on, I would happily accept PRs to improve the parsers and publish it as a library. Though to be honest, it is currently very far from being a full-fledged SQL parser of postgres and I doubt it will be