I'm trying to use SQLAlchemy's insert and execute methods with a list of dictionaries as the values, and to get back the inserted ids. The database is Postgres, which should support RETURNING.
The code looks more or less like this:
table = MyThing.__table__
insert_stmt = table.insert().values({"name": bindparam("name_val")}).returning(table.c.id)
values = [{"name_val": "a"}, {"name_val": "b"}]
result = session.execute(insert_stmt, values).fetchall()
(trimmed down for readability and some obfuscation)
When the value list is bigger than one (as in the example above) I get:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) no results to fetch
but when the list only have one value the new id is returned properly.
I understand that I probably missed something in the way I'm using returning but I can't figure out what.