You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
executemany not discarding result aka fetchmany #137
Can I suggest a new section for docs "example of sql with asyncpg"? I know this is technically an issue with my knowledge of postgres not asyncpg, but such a section would ease the learning curve of using asyncpg a lot and avoid you having to answer these questions.
Is it possible to accomplish this same executemany with RETURNING while passing in a list of dicts/mappings?
For the pyscopg2 alternative, it would be usingpsycopg2.extras.execute_values which requires a template of the columns. This then supports default values.
INSERT INTO persons (lastname, firstname) VALUES ($1, $2) RETURNING id;
data = [
('doe', 'john'),
('doe', 'jane'),
...
]
I was looking for fetchmany intuitively, without luck, so I landed here :) I think a fetchmany function would be really handy for situations like this.
I ended up looping over the list of persons executing a single fetch call for each.
Reacted by Julien Brayere, Artem Streltsov, Igor Nehoroshev, komendantyan and Artem
if its possible, you may use asyncpg with jinjasql
we have workaround for such cases
insert into ...
values
{% for row in data %}
({{ row.column1 }}, {{ row.column2 }})
{% if not loop.last %}, {% endif %}
{% endfor %}
returning column1, column2
Activity
elprans commentedon May 11, 2017
Try this:
samuelcolvin commentedon May 11, 2017
Thanks, that got me to the solution, I actually needed
(Note the
::TEXT[])Can I suggest a new section for docs "example of sql with asyncpg"? I know this is technically an issue with my knowledge of postgres not asyncpg, but such a section would ease the learning curve of using asyncpg a lot and avoid you having to answer these questions.
elprans commentedon May 11, 2017
Yes, I'm actually working on it right now.
jaredvacanti commentedon Mar 28, 2018
Is it possible to accomplish this same
executemanywithRETURNINGwhile passing in a list of dicts/mappings?For the pyscopg2 alternative, it would be using
psycopg2.extras.execute_valueswhich requires a template of the columns. This then supports default values.feluxe commentedon Nov 12, 2018
I'm having the same problem with this query:
INSERT INTO persons (lastname, firstname) VALUES ($1, $2) RETURNING id;I was looking for
fetchmanyintuitively, without luck, so I landed here :) I think afetchmanyfunction would be really handy for situations like this.I ended up looping over the list of persons executing a single
fetchcall for each.jiamo commentedon Nov 8, 2019
Any new progress?
shurshilov commentedon Dec 2, 2024
Any news???
jabajke commentedon Jan 10, 2025
if its possible, you may use asyncpg with jinjasql
we have workaround for such cases
prbly it would be useful for someone
elprans commentedon Jan 10, 2025
This was implemented in #1175 (as
fetchmany).