diff --git a/Lib/sqlite3/_completer.py b/Lib/sqlite3/_completer.py index ba580f968bf92dc..12cafc26602f8bb 100644 --- a/Lib/sqlite3/_completer.py +++ b/Lib/sqlite3/_completer.py @@ -48,7 +48,7 @@ def _complete(con, text, state): f"""\ SELECT pti.name || ' ' FROM "{schema}".sqlite_master AS sm JOIN pragma_table_xinfo(sm.name,'{schema}') AS pti - WHERE sm.type='table' AND + WHERE sm.type IN ('table', 'view') AND pti.name LIKE REPLACE(:text, '_', '^_') || '%' ESCAPE '^'""" for schema in schemata ) diff --git a/Lib/test/test_sqlite3/test_cli.py b/Lib/test/test_sqlite3/test_cli.py index 0d235d90f1101b4..e049d16642ce0ca 100644 --- a/Lib/test/test_sqlite3/test_cli.py +++ b/Lib/test/test_sqlite3/test_cli.py @@ -326,6 +326,8 @@ def test_complete_columns(self): input_ = textwrap.dedent("""\ CREATE TABLE _table (_col_table); CREATE TEMP TABLE _temp_table (_col_temp); + CREATE VIEW _view AS SELECT _col_table AS _col_table_alias + FROM _table; ATTACH ':memory:' AS attached; CREATE TABLE attached._attached_table (_col_attached); @@ -340,9 +342,9 @@ def test_complete_columns(self): candidates = [l.strip() for l in lines[start+1:end]] self.assertEqual( - candidates, ["_col_attached", "_col_table", "_col_temp"] + candidates, + ["_col_attached", "_col_table", "_col_table_alias", "_col_temp"], ) - @unittest.skipIf(sqlite3.sqlite_version_info < (3, 30, 0), "PRAGMA function_list is not available until " "SQLite 3.30.0") diff --git a/Misc/NEWS.d/next/Library/2026-09-27-14-00-00.gh-issue-158277.aBcDeF.rst b/Misc/NEWS.d/next/Library/2026-09-27-14-00-00.gh-issue-158277.aBcDeF.rst new file mode 100644 index 000000000000000..7f0434aeea67081 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-09-27-14-00-00.gh-issue-158277.aBcDeF.rst @@ -0,0 +1,3 @@ +Fix :mod:`sqlite3` CLI completer to include view columns in +column-name completion. +