Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib sqlite3 executemany() does not support RETURNING statement #100021

Open
zentarim opened this issue Dec 5, 2022 · 0 comments
Open

stdlib sqlite3 executemany() does not support RETURNING statement #100021

zentarim opened this issue Dec 5, 2022 · 0 comments
Labels
expert-sqlite3 type-bug An unexpected behavior, bug, or error

Comments

@zentarim
Copy link

zentarim commented Dec 5, 2022

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!

@zentarim zentarim added the type-bug An unexpected behavior, bug, or error label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expert-sqlite3 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants