Closed
Description
Problem
sqlite3.Connection.executemany()
does not support a RETURNING
statement. All requests containing it fail with an exception:
sqlite3.ProgrammingError: executemany() can only execute DML statements.
Working shell example
#!/bin/sh
rm -f ./test.db
sqlite3 ./test.db <<EOF
CREATE TABLE releases (
component VARCHAR(64) NOT NULL,
version VARCHAR(64) NOT NULL,
os VARCHAR(64) NOT NULL,
PRIMARY KEY (component, version, os));
INSERT INTO releases VALUES('server', '1.0.0', 'Unix'), ('server', '1.0.0', 'NT') RETURNING *;
EOF
Produces a relevant output:
server|1.0.0|Unix
server|1.0.0|NT
However, a Python example doing similar thing:
#!/bin/env python3.10
from pathlib import Path
import sqlite3
if __name__ == '__main__':
test_file = Path.cwd() / 'test.db'
test_file.unlink(missing_ok=True)
connection = sqlite3.connect(test_file)
connection.execute(
'CREATE TABLE releases ('
'component VARCHAR(64) NOT NULL, '
'version VARCHAR(64) NOT NULL, '
'os VARCHAR(64) NOT NULL, '
'PRIMARY KEY (component, version, os));',
)
values = [
('server', '1.0.0', 'Unix'),
('server', '1.0.0', 'NT')
]
cursor = connection.executemany('INSERT INTO releases VALUES(?, ?, ?) RETURNING *;', values)
print(cursor.fetchall())
generates an exception:
Traceback (most recent call last):
File "/home/zentarim/py/test/./sql_many.py", line 20, in <module>
cursor = connection.executemany('INSERT INTO releases VALUES(?, ?, ?) RETURNING *;', values)
sqlite3.ProgrammingError: executemany() can only execute DML statements.
Environment
Ubuntu 22.04.1 LTS
Kernel 6.0.0-1006-oem
Python 3.10.6
sqlite3 module version: 2.6.0
sqlite3 package version: 3.37.2
Not sure if it is a bug or unimplemented feature.
Thanks in advance!
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done