databases icon indicating copy to clipboard operation
databases copied to clipboard

execute_many should not discard results

Open charterchap opened this issue 4 years ago • 3 comments

consider the following:

CREATE TABLE my_table
(
  id  BIGSERIAL,
 item INTEGER
)
query = """
            INSERT INTO 
            my_table (item)
            VALUES (:item) RETURNING id
            """
values=[{'item':100, 'item':200}]
my_ids = database.execute_many(query=query,values=values)

I would want to get the id for each value.

https://github.com/encode/databases/blob/45519d7ea1183d8d1ce24de21836ccb7c2174039/databases/backends/postgres.py#L182

charterchap avatar Jun 04 '20 15:06 charterchap

Did anything changed? For now using fetch_all instead of execute_all is working for me.

activity_query = models.activities.insert().values(activity_values).returning(models.activities.c.id)
result = await database.fetch_all(query=activity_query)

psowa001 avatar Feb 01 '21 15:02 psowa001

I'm new to this, but it seems that DBAPI defines executemany() to have undefined behavior when returning one or more result sets. Does execute_many() in databases comply with DBAPI?

barius avatar Jul 05 '21 07:07 barius

+1

grafke avatar Dec 20 '22 15:12 grafke