Sqlite. How to create an index in a connected database?

I had a problem adding an index database to the memory attached to the main database.

1) I open the database (F) from the file

2) Attach the database: memory: (M)

3) Creating tables in the database M

4) Copy data from F to M

I would also like to create an index in the M database, but don't know how to do it. This code creates an index, but in database F:

sQuery = "CREATE INDEX IF NOT EXISTS [INDID] ON [PANEL]([ID] ASC);"; 

I tried adding a classifier of names in front of the table name as follows:

 sQuery = "CREATE INDEX IF NOT EXISTS [INDID] ON [M.PANEL]([ID] ASC);"; 

but SQLite returns a message with the header main.M.PANEL.

What can I do?

+4
source share
1 answer

just put the square brackets around the prefix [M]. [panel] or just skip them

UPD: you shoud set the prefix before the name index instead of the table name:

 sqlite> attach database ":memory:" as m; sqlite> .databases seq name file --- --------------- ---------------------------------------------- 0 main 2 m sqlite> create table m.users (id int, name TEXT); sqlite> create unique index m.qwe on users (name); sqlite> insert into m.users VALUES(2,'asd'); sqlite> insert into m.users VALUES(3,'asd'); Error: column name is not unique 
+7
source

Source: https://habr.com/ru/post/1381271/


All Articles