peewee.OperationalError: too many SQL variables PLUS
See original GitHub issueHi there:
I’m using peewee to insert files into SQLite, I meet this error: peewee.OperationalError: too many SQL variables . I tried Google, some said it’s because the SQLITE_MAX_VARIABLE_NUMBER.
So i searched and using this code to get the SQLITE_MAX_VARIABLE_NUMBER.
def max_sql_variables():
"""Get the maximum number of arguments allowed in a query by the current
sqlite3 implementation. Based on `this question
`_
Returns
-------
int
inferred SQLITE_MAX_VARIABLE_NUMBER
"""
import sqlite3
db = sqlite3.connect(':memory:')
cur = db.cursor()
cur.execute('CREATE TABLE t (test)')
low, high = 0, 100000
while (high - 1) > low:
guess = (high + low) // 2
query = 'INSERT INTO t VALUES ' + ','.join(['(?)' for _ in range(guess)])
args = [str(i) for i in range(guess)]
try:
cur.execute(query, args)
except sqlite3.OperationalError as e:
if "too many SQL variables" in str(e):
high = guess
else:
raise
else:
low = guess
cur.close()
db.close()
return low
SQLITE_MAX_VARIABLE_NUMBER = max_sql_variables()
And i get the value is 999. Then I tried the following steps:
... code omit...
for _fileList in _list:
print "Insert %s Records" % len( _fileList )
FileLite.fromFileList( _fileList )
(1) I split my file list to 400, But it still said peewee.OperationalError: too many SQL variables
(2) I split my files list to 100,it still said peewee.OperationalError: too many SQL variables
(3) I split my files list into 80, It’s OK!
(4) I increase the value to 84, It seems OK and insert some data, but when the loops goes on, the peewee.OperationalError: too many SQL variables
throws, HOW COULD THIS HAPPEN?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
peewee.OperationalError: too many SQL variables on upsert ...
After some investigation, the problem appears to be related with the maximum number of parameters that a sql query can have: SQLITE_MAX_VARIABLE_NUMBER.
Read more >How to increase SQLITE_MAX_VARIABLE_NUMBER at ...
I'm using Python and the Peewee module to manage a Sqlite3 database. ... questions/35616602/peewee-operationalerror-too-many-sql-variables ...
Read more >peewee.OperationalError: too many SQL variables - 华为云社区
使用peewee+sqlite批量插入数据报错peewee.OperationalError: too many SQL variables ...
Read more >Is there a way to create a parameterized query or stored ...
OperationalError "too many SQL variables" when selecting rows from given range · How to solve ... It shouldn't make too much of a...
Read more >herman - PyPI
a little fork of peewee. ... peewee.OperationalError: no such column: t2.name ... DataError: Too many instances matching query exist: SQL: SELECT p1.id, p1....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be great if peewee could automatically batch up inserts upon the
insert_many
call (peewee is in a better position to count accurately the number of used SQL variables)As far as I can tell this is not a Peewee issue, but running into limits imposed by SQLite.