Skip to content

Suggest columns after a column named type#1611

Open
Sanjays2402 wants to merge 1 commit into
dbcli:mainfrom
Sanjays2402:fix/type-column-completion
Open

Suggest columns after a column named type#1611
Sanjays2402 wants to merge 1 commit into
dbcli:mainfrom
Sanjays2402:fix/type-column-completion

Conversation

@Sanjays2402

Copy link
Copy Markdown

Fixes #1412

Description

type is a non-reserved word in postgres, so sqlparse tags a column literally named type as the TYPE keyword. suggest_based_on_last_token matched that token unconditionally, so a query like SELECT 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

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected (new test_column_named_type_still_suggests_columns fails on main for all three cases and passes with the fix; the full completion suite, 2359 tests, is green).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocomplete offers no columns after one column named 'type'

1 participant