-
Notifications
You must be signed in to change notification settings - Fork 418
executemany not discarding result aka fetchmany #137
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
Try this: await conn.fetch('''
INSERT INTO people (name) (SELECT unnest ($1))
RETURNING id
''', ['anne', 'ben', 'charlie']) |
Thanks, that got me to the solution, I actually needed await db_conn.fetch("""
INSERT INTO recipients (address) (SELECT unnest ($1::TEXT[]))
RETURNING id, address
""", ['anne', 'ben', 'charlie']) (Note the 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. |
Yes, I'm actually working on it right now. |
Is it possible to accomplish this same For the pyscopg2 alternative, it would be using |
I'm having the same problem with this query:
I was looking for I ended up looping over the list of persons executing a single |
Any new progress? |
Any news??? |
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 prbly it would be useful for someone |
This was implemented in #1175 (as |
With the following query
and values to create
[('anne',), ('ben',), ('charlie',)]
.I believe there's currently no way with asyncpg to execute this single query and get all the ids returned.
I've tried:
executemany
but the result is discardedfetch
but that doesn't extend to executing manyfetch
while casting the argument to an array::TEXT[][]
but I either get a syntax error or a single value of the stringified list insert.In short: would it be possible for
executemany
to return the result?The text was updated successfully, but these errors were encountered: