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

Using INSERT RETURNING seems to break sqlite3 #54

Open
ghallberg opened this issue Jul 23, 2021 · 2 comments
Open

Using INSERT RETURNING seems to break sqlite3 #54

ghallberg opened this issue Jul 23, 2021 · 2 comments

Comments

@ghallberg
Copy link

ghallberg commented Jul 23, 2021

I'm trying to write an INSERT RETURNING query which works on both Postgres and SQLite:

-- :name test_insert :insert
INSERT INTO table (foo) VALUES (:bar) RETURNING id;

This causes a sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) cannot commit transaction - SQL statements in progress error.

It's possible this is related to sqlalchemy/sqlalchemy#6195

@mcfunley
Copy link
Owner

Looks like the underlying issue isn't fixed yet (haven't had time to really dig here), but in the meantime you should be able to drop the RETURNING id -- for engines that support lastrowid, insert statements already return the ID of the last row inserted.

https://github.com/mcfunley/pugsql/blob/master/pugsql/statement.py#L94

@an-ivanov
Copy link

The same bug has not been fixed yet for the UPDATE RETURNING combination :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants