gpt4 book ai didi

sqlite - "Error: unable to open database file"用于 GROUP BY 查询

转载 作者:行者123 更新时间:2023-12-03 18:25:04 26 4
gpt4 key购买 nike

我有一个 python 脚本,它从一些外部数据创建一个 sqlite 数据库。这工作正常。但是每次我在这个数据库上执行 GROUP BY 查询时,我都会收到“错误:无法打开数据库文件”。正常的 SELECT 查询工作。

这对于 python 的 sqlite3 库和 sqlite3 cli 二进制文件都是一个问题:

sqlite> SELECT count(*) FROM REC;
count(*)
----------
528489
sqlite> SELECT count(*) FROM REC GROUP BY VERSION;
Error: unable to open database file
sqlite>

我知道这些错误通常是权限错误(我已经阅读了我在 StackOverflow 上可以找到的关于此主题的所有问题),但我很确定这不是我的情况:
  • 我说的是易于创建的数据库和读取请求
  • 我检查了权限:文件及其包含的文件夹都设置了写权限
  • 我什至可以写入数据库:创建新表没问题。
  • 该设备未满,它有足够的空间。
  • 最佳答案

    确保您的进程有权访问 TEMP 目录。

    来自 SQLite's Use Of Temporary Disk Files文档:

    SQLite may make use of transient indices to implement SQL language features such as:

    • An ORDER BY or GROUP BY clause
    • The DISTINCT keyword in an aggregate query
    • Compound SELECT statements joined by UNION, EXCEPT, or INTERSECT

    Each transient index is stored in its own temporary file. The temporary file for a transient index is automatically deleted at the end of the statement that uses it.



    您可能可以通过设置 temp_store pragma 来验证临时存储是否是问题所在。至 MEMORY :
    PRAGMA temp_store = MEMORY;

    告诉 SQLite 保留 GROUP BY 的临时索引内存中的条款。

    或者,在要分组的列上创建显式索引,以防止创建临时索引。

    关于sqlite - "Error: unable to open database file"用于 GROUP BY 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16190471/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com