Closed
Description
How to insert multiple rows without a traditional for loop?
Something like executemany
in psycopg2
I am asking because I failed to find any example or method in the documentation.
Actually what I am doing is:
async def insertdemo(data, dns=DNS):
async with asyncpg.create_pool(dns) as pool:
async with pool.acquire() as con:
async with con.transaction():
stmt = '''insert into demo (num, name) select * from unnest($1::int[], $2::varchar[]);'''
await con.execute(stmt, *zip(*data))
I would like to avoid to unzip the data array.