Escape table name of attached database in SQLite?

对着背影说爱祢 提交于 2019-12-12 07:01:05

问题


According to this answer, you can escape a table name by putting double-quotes around it. The SQLite documentation further states that brackets and back-ticks are also possible for compatibility with other systems.

This works on tables from the current database, however, when I try to do this on an attached database I get an error:

ATTACH db2 AS x; SELECT * FROM "x.table1";

yields the error:

no such table: x.table1

If I remove the "x." and run the query directly on database db2, it works.

So how do I escape the table name when it is part of an attached database?

I have tried the brackets and backticks, and I have also tried quoting only the table name and not the "x." part, e.g. all of the following:

ATTACH db2 AS x; SELECT * FROM `x.table1`;
ATTACH db2 AS x; SELECT * FROM [x.table1];
ATTACH db2 AS x; SELECT * FROM x."table1";
ATTACH db2 AS x; SELECT * FROM x.`table1`;
ATTACH db2 AS x; SELECT * FROM x.[table1];

None of these work.


回答1:


Works for me:

select * from "x"."table1";



来源:https://stackoverflow.com/questions/35467644/escape-table-name-of-attached-database-in-sqlite

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