Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite too many terms in compound SELECT

Tags:

android

sqlite

In my Android SQLite databese query I have an INSERT INTO statement followed by about 600 ('data1'),('data2')... tags, generated by code.

After db.exec(sql) I got this error: "too many terms in compound SELECT (code1); while compiling INSERT INTO.. "

Is there any way to increase this limitation?

like image 976
user3864532 Avatar asked Aug 12 '14 06:08

user3864532


People also ask

What is the main limitation of SQLite?

An SQLite database is limited in size to 281 terabytes (248 bytes, 256 tibibytes). And even if it could handle larger databases, SQLite stores the entire database in a single disk file and many filesystems limit the maximum size of files to something less than this.

How many entries can SQLite handle?

When used with the maximum page size of 65536, this gives a maximum SQLite database size of about 281 terabytes. The max_page_count PRAGMA can be used to raise or lower this limit at run-time. The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19).

How do I reduce the size of my SQLite database?

Use Rust To Reduce The Size Of Your SQLite Database. Meet sqlite-zstd, a Rust library that compresses your database many fold, leading to great savings in size while conserving its search capabilities intact.

What is the maximum size of varchar in SQLite?

(9) What is the maximum size of a VARCHAR in SQLite? SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact.


1 Answers

The limit SQLITE_MAX_COMPOUND_SELECT cannot be raised at runtime,

So you need to split your inserts into batches of 500 rows each. This will be more efficient than inserting one row per query. For e.g.

BEGIN TRANSACTION
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
INSERT INTO tablename (data1,data2) VALUES ("data1","data2")
...
END TRANSACTION

Also see Insert Multiple Rows in SQLite

like image 82
Giru Bhai Avatar answered Oct 07 '22 22:10

Giru Bhai