-
Notifications
You must be signed in to change notification settings - Fork 606
Add FETCH/OFFSET and JOIN LATERAL (subquery) #69
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
Conversation
Pull Request Test Coverage Report for Build 223
💛 - Coveralls |
Thanks for the PR! I'm sorry it took so long to get back to you - I wasn't familiar with this syntax and got distracted by the other PRs... I only looked into the FETCH/OFFSET patch, not the LATERAL DERIVED bit. My comment grew larger than I intended, but the gist is: I would update the syntax comments (1) and settle the I'd also like to coordinate merges with @benesch, per discussion in #84.
|
BTW: Yes, it's fine. I was thinking of removing the global keywords list altogether. |
I've made the two changes you suggested, I find having percent as a boolean much simpler to use and having more specific comments is good. I added support for parsing fetch without a quantity, I represent this by having Other improvements I agree should be discussed in a new issue. On the lateral derived, I apologize for throwing this into the PR. I needed lateral joins for the project I am using sqlparser for, so I built it in my fork of the repository. I am still relatively new to open source workflows, but I imagine I am supposed to make a branch for the lateral derived feature? LATERAL is actually very simple to parse (just check for LATERAL then parse a subquery). I think the AST for LateralDerived is simple enough and I have a test passing for parsing a lateral subquery. All in all the branch is ready to merge and we can create an issue to discuss what to do with FETCH, LIMIT and OFFSET improvements. |
This looks great to me! I think the support for LATERAL derived queries here is sufficient to parse all LATERAL-ness present in the SQL spec, but Postgres, if I'm reading things right, allows LATERAL to apply to any JOIN factor, not just derived factors: https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-LATERAL. Let's punt that to later work, though. I think we'll need to tweak the structure of I'll leave it to @nickolay to double-check, but I do believe you've addressed everything he requested! |
d169569
to
1f6da84
Compare
@thomas-jeepe, just a heads up that I force-pushed a rebase that mostly cleans up the Git history. The FETCH and OFFSET support is isolated to the first commit now, and LATERAL support to the second. I didn't make any code changes to FETCH and OFFSET, but I did adjust the LATERAL support to use a |
@benesch Thanks for the comments and review! I agree on the lateral boolean field, it definitely looks more concise and cleaner. Thanks for the rebase as well! |
Merged, thanks! |
I've added code and passing tests for this, just two points which should be gone over.
First is the ambiguity of the sql spec. Per the ANSI SQL:2011 standard, there is no limit clause, and the order seems to be set in stone.
Obviously, many databases and currently sqlparser support the LIMIT clause.
POSTGRES seems to support OFFSET without {ROW | ROWS}. LIMIT, OFFSET, FETCH can be reordered in POSTGRES. Having all of LIMIT, OFFSET and FETCH causes a parsing error.
I've implemented it in such a fashion that you can't reorder those clauses and so that you can have all of LIMIT, OFFSET and FETCH. I don't support OFFSET without {ROW | ROWS}
Another point is keywords, in sqlparser, no distinction is made between reserved and non-reserved words. I added a couple new keywords to the keyword list, I hope this should be fine.