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

Document how to confirm that INSERT worked with prepared statement #1108

Open
mbrancato opened this issue Nov 21, 2023 · 2 comments
Open

Document how to confirm that INSERT worked with prepared statement #1108

mbrancato opened this issue Nov 21, 2023 · 2 comments

Comments

@mbrancato
Copy link

When using execute() I can parse the command output for INSERT to confirm a single row inserted like INSERT 0 1. However, execute() does not support the LRU for automatically prepared statements. Can you document how to confirm that the INSERT worked using a fetch*() method that will use the LRU? I do sometimes see INSERT 0 0 results in some high-volume workloads (likely just duplicate data), and these do not raise UniqueViolationError, QueryCanceledError, or some TimeoutError.

@elprans
Copy link
Member

elprans commented Nov 21, 2023

execute() uses prepared statements if there are arguments, which is likely in the case of insert.

I do sometimes see INSERT 0 0 results in some high-volume workloads

Depending on how your insert body looks it's totally possible to insert zero rows. For example, INSERT INTO foo (select * where false) will return INSERT 0 0.

@mbrancato
Copy link
Author

@elprans ahh thanks, I was going by the documentation which excludes execute() for the built-in LRU cache of prepared statements and only includes fetch*().

asyncpg automatically maintains a small LRU cache for queries executed during calls to the fetch(), fetchrow(), or fetchval() methods.

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

No branches or pull requests

2 participants