Skip to content
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

"Cannot insert multiple commands into prepared statement" issue while executing query with params #30

Open
coldmind opened this issue Sep 14, 2016 · 3 comments
Labels

Comments

@coldmind
Copy link

(python 3.5.1, asyncpg 0.5.4)

Consider the next code

import asyncpg
import asyncio

async def run():
    con = await asyncpg.connect(user="coldmind", database="test")
    await con.execute('SELECT ($1); SELECT 2;', 1)
asyncio.get_event_loop().run_until_complete(run())

The executing fails with asyncpg.exceptions.PostgresSyntaxError: cannot insert multiple commands into a prepared statement error, while the another example (without passing params to the query) works well with multiple commands:

import asyncpg
import asyncio


async def run():
    con = await asyncpg.connect(user="coldmind", database="test")
    await con.execute('SELECT 1; SELECT 2;')
asyncio.get_event_loop().run_until_complete(run())

Why is the first example using a prepared statement instead of executing it?

@coldmind coldmind changed the title Insert multiple commands into prepared statement issue while executing query with params "Cannot insert multiple commands into prepared statement" issue while executing query with params Sep 14, 2016
@elprans
Copy link
Member

elprans commented Sep 15, 2016

Parameters are only supported in prepared statements, and there can be only one command per prepared statement. This is a PostgreSQL protocol limitation. asyncpg does not itself attempt to mogrify the query. We may implement that at some point (see also #9).

@coldmind
Copy link
Author

Got it.
Maybe documentation should be clearer and will contain a note that prepared statement will be executed in that case.

@crazyhouse33
Copy link

I have the same problem with fetch( cant even do 2 selects). Is there a way of inserting stuff while using RETURNING clause while doing other queries ? I mean is there a non prepared version of fetch? The obvious workaround would be to to parse every query provided to broke them into individuals queries, but I would rather just desactive the auto prepared-statement mechanism if it is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants