Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sebastian opened this issue Jan 13, 2021 · 1 comment
Open

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

sebastian opened this issue Jan 13, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sebastian
Copy link

sebastian commented Jan 13, 2021

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
Copy link
Owner

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

@Zaid-Ajaj Zaid-Ajaj added enhancement New feature or request good first issue Good for newcomers labels Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants