【发布时间】:2022-01-21 21:23:31
【问题描述】:
我遇到了一个奇怪的问题。在 TablePlus 中,当我运行以下命令时,它会返回表,但相同的查询在 Python 中不起作用。
SELECT
name
FROM
sqlite_schema
WHERE
type ='table'
AND
name NOT LIKE 'lookup%';
Python代码如下:
def get_connection():
path = 'data.sqlite3'
connection = sqlite3.connect(path)
return connection
sql_select = "SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'lookup%';"
cursor = connection.execute(sql_select)
错误:
cursor = connection.execute(sql_select)
sqlite3.OperationalError: no such table: sqlite_schema
我正在使用 SQLite 3.36
【问题讨论】:
-
sqlite.org/schematab.html - 查看第 2 段的替代名称
-
@balderman 所以
sqlite_master工作。但是为什么sqlite_schema在 TablePlus 中为同一个数据库工作,但在 Python 中却不行? -
我不知道.. :-)
-
您可能在 TablePlus 中使用 3.36 版本,但 Python 版本比这更旧。
select sqlite_version();在 Python 中返回什么? -
@MarkBenningfield 3.29.0