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

。_饼干妹妹 提交于 2019-12-13 02:49:45

问题


using tcl and sqlite3 I would like to create a temporary table in memory. Trying this:

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

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

Gives me an error: near "values": syntax error This I gues has to do with that "values" is a reserved keyword in sqlite. Changing the above code to:

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

gives me the error "temporary table name must be unqualified"

But skipping the memdb. in front of things would put the new table in the regular on disk database.... What is it I am doing wrong here?


回答1:


Temporary tables go into the temporary database (which is named temp). While that database is stored in a disk file, the file is not actually written to until the cache overflows (because the temporary database is not required to be durable through a crash).

If you want to put the table into some other database, do not use CREATE TEMP TABLE but the normal 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"


来源:https://stackoverflow.com/questions/52459126/using-tcl-sqlite-syntax-error-when-creating-table-in-memory-temp-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!