Suggest columns after GROUP BY#1599
Open
Kynde wants to merge 1 commit into
Open
Conversation
The completion engine offers columns after SELECT, WHERE, HAVING, ORDER BY and DISTINCT, but GROUP BY was missing from that list, so `SELECT ... FROM tbl GROUP BY <tab>` fell through to FROM-clause handling and suggested tables/schemas instead of columns. Add "group by" to the keyword tuple so it suggests columns like ORDER BY already does, and extend the existing alias tests to cover it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Suggest columns after
GROUP BY, the same way pgcli already does forORDER BY.Why
The completion dispatch in
suggest_based_on_last_tokenoffers column suggestions forSELECT,WHERE,HAVING,ORDER BYandDISTINCT, butGROUP BYwas missing from that keyword tuple. As a result, a query like:fell through to the generic keyword handling and ultimately re-derived its suggestions from the
FROMclause — offering tables/schemas instead of the table's columns.ORDER BY,HAVINGandWHEREin the same position all correctly suggest columns.This appears to have been the case in every release I checked (3.5.0 through current
main); it's a long-standing omission rather than a recent regression.Change
"group by"to the keyword tuple inpgcli/packages/sqlcompletion.pyso it routes through_suggest_expression, exactly likeORDER BY.test_distinct_and_order_by_suggestions_with_aliasesand..._with_alias_givenparametrized tests withGROUP BYcases (both bareGROUP BYand qualifiedGROUP BY x.).Testing
pytest tests/→ 2699 passed, 1 xfailed, 1 xpassed (pre-existing).ruff format --checkandruff checkclean on the changed files.