使用 TCL:在内存临时 table 中创建 table 时出现 Sqlite 语法错误

Using TCL: Sqlite syntax error when creating table in memory temp table

使用 tcl 和 sqlite3 我想在内存中创建一个临时 table。试试这个:

package require sqlite3
sqlite3 DB  [file normalize X:\memdbtest.db]

DB eval {
    ATTACH DATABASE ':memory:' AS memdb;
    CREATE TEMP TABLE memdb.values (val TEXT);
}

给我一个错误:"values"附近:语法错误 我猜这与 "values" 是 sqlite 中的保留关键字有关。将以上代码更改为:

    DB eval {
        ATTACH DATABASE ':memory:' AS memdb;
        CREATE TEMP TABLE memdb.things (val TEXT);
    }

给我错误 "temporary table name must be unqualified"

但是跳过了 memdb。前面的东西会把新的 table 放在磁盘数据库中的常规....我在这里做错了什么?

临时 table 进入 temporary database(名为 temp)。 虽然该数据库存储在磁盘文件中,但直到缓存溢出时才真正写入文件(因为临时数据库不需要在崩溃时保持持久性)。

如果要将 table 放入其他数据库,请不要使用 CREATE TEMP TABLE,而是使用正常的 CREATE TABLE

CREATE TABLE things([...]);        -- creates the table in the DB "main"
CREATE TABLE memdb.things([...]);  -- creates the table in the specified DB
CREATE TEMP TABLE things([...]);   -- creates the table in the DB "temp"
CREATE TABLE temp.things([...]);   -- creates the table in the DB "temp"