-
Notifications
You must be signed in to change notification settings - Fork 420
Investigate the feasibility of implementing executemany
#36
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
Comments
According to https://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/ However, it would be good to have at least
can be executed as
where BTW. How |
Also, looking at http://initd.org/psycopg/docs/usage.html
so |
What about changing
If |
asyncpg explicitly supports prepared statements, so there is no need for a dedicated ps = await conn.prepare('INSERT INTO test(num, data) VALUES($1, $2)')
for row in data:
await ps.fetchval(*row) Or, since the statements are prepared by default, you can use even simpler form: for row in data:
await conn.execute('INSERT INTO test(num, data) VALUES($1, $2)', *row) |
IMHO, dedicated
than the whole loop. If this was implemented at Cython level, wouldn't it be faster as well? I hope you do not mind, I will repeat the question from my first comment - are the rows iterated in the loop sent one by one or are the statements batched? |
No, high-level APIs in asyncpg are not Cythoned, and even if they were, the perf difference would be minimal.
There is no such thing as batching, That said, event loop overhead needs to be benchmarked for this case. If it turns out to be significant, we will look into implementing the Meanwhile you can create a helper method using the loop technique mentioned above. |
executemany
The executemany() method runs an SQL command for each sequence of arguments in the given iterable. Closes: #36
The executemany() method runs an SQL command for each sequence of arguments in the given iterable. Closes: #36
The executemany() method runs an SQL command for each sequence of arguments in the given iterable. Closes: #36
The executemany() method runs an SQL command for each sequence of arguments in the given iterable. Closes: #36
How to insert multiple rows without a traditional for loop?
Something like
executemany
in psycopg2I am asking because I failed to find any example or method in the documentation.
Actually what I am doing is:
I would like to avoid to unzip the data array.
The text was updated successfully, but these errors were encountered: