使用TCL:在内存临时表中创建表时,Sqlite语法错误 [英] Using TCL: Sqlite syntax error when creating table in memory temp table

查看:101
本文介绍了使用TCL:在内存临时表中创建表时,Sqlite语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);
}

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

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"

但是跳过memdb。前面的事情会将新表放到磁盘数据库的常规数据库中。...我在这里做什么错了?

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?

推荐答案

临时表进入临时数据库(名为 temp )。
该数据库存储在磁盘文件中时,直到高速缓存溢出为止才真正写入该文件(因为临时数据库不需要因崩溃而保持持久性)。

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).

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

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"

这篇关于使用TCL:在内存临时表中创建表时,Sqlite语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆