Is it possible to create a VIEW (not temporary view) in a Sqlite database that has other databases attached to it? The view should be able to access data from all databases via joined tables.
Asked
Active
Viewed 6,247 times
1 Answers
16
No, the view must be temporary, otherwise an error will occur:
sqlite> create view view1 as select * from db2.foo union select * from main.foo;
Error: view view1 cannot reference objects in database db2
sqlite> create temp view view1 as select * from db2.foo union select * from main.foo;
sqlite> select * from view1;
...
This makes sense since a temporary view is part of the automatically created temp
database which only exists for the current process.
EDIT:
You can list the temporary tables and views (all stored in the automatically created temp
database) this way:
sqlite> .headers on
sqlite> select * from sqlite_temp_master;
type|name|tbl_name|rootpage|sql
view|view1|view1|0|CREATE VIEW view1 as select * from db2.foo union select * from main.foo
To list views only:
select * from sqlite_temp_master where type='view';
-
Is it possible to get a list of these views, then? – Interfector May 02 '12 at 08:36
-
Fantastic. Makes a ton of sense and thanks for explaining it as well. – Dev Kanchen Aug 06 '12 at 04:40
-
Related feature request for Navicat: https://community.navicat.com/forum/navicat-sales-and-feedback/feedback/5144-possibility-to-save-views-that-reference-attached-databases – Stefan Jul 19 '18 at 13:46