Skip to content

sqlite3 CLI completer: include views in column completion #158277

Description

@Tony123-tech

Bug description:

_complete() in Lib/sqlite3/_completer.py restricts column-name
completion to entries in sqlite_master with type='table'. Views
(type='view') are excluded, even though pragma_table_xinfo returns
their columns. The comment above the block already states the intent to
cover views:

# tables, indexes, triggers, and views

Reproducer:

import sqlite3
from sqlite3._completer import _complete

con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t (a INTEGER, b INTEGER)")
con.execute("CREATE VIEW v AS SELECT a, b, a + b AS sum_ab FROM t")
print(_complete(con, "sum", 0))  # 'SUM('
print(_complete(con, "sum", 1))  # None
con.close()

Expected: _complete(con, "sum", 1) returns 'sum_ab ' (the view column).
Actual: only 'SUM(' is returned.

Fix:
diff

  •                WHERE sm.type='table' AND
    
  •                WHERE sm.type IN ('table', 'view') AND
    

CPython versions tested on:
CPython main branch

Operating systems tested on:
macOS

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-sqlite3type-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions