Suggest columns after a column named type#1611
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
sqlparse tags a column literally named "type" as the TYPE keyword because type is non-reserved in postgres. suggest_based_on_last_token matched that token unconditionally, so the SELECT list switched to datatype/table/schema suggestions and offered no columns for the rest of the query. The TYPE keyword only introduces a datatype in DDL contexts, so only treat it as such when the preceding keyword is not a DML statement keyword. Cast operators and parenthesized column lists are unaffected. Fixes dbcli#1412
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.
Fixes #1412
Description
typeis a non-reserved word in postgres, so sqlparse tags a column literally namedtypeas the TYPE keyword.suggest_based_on_last_tokenmatched that token unconditionally, so a query likeSELECT type,switched to datatype/table/schema suggestions and offered no column completions for the rest of the statement.TYPE only introduces a datatype in DDL contexts (
ALTER COLUMN bar TYPE,SET DATA TYPE), so it is now only treated that way when the preceding keyword is not a DML statement keyword. Cast operators (::) and parenthesized column lists (CREATE TABLE foo (bar) go through separate paths and are unaffected.Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).test_column_named_type_still_suggests_columnsfails onmainfor all three cases and passes with the fix; the full completion suite, 2359 tests, is green).