Repository navigation
Conversation
DBInterface.execute always uses the extended protocol, so a string holding several statements fails with 42601 "cannot insert multiple commands into a prepared statement". libpq runs the same string with PQexec over the simple-query protocol, which is how migration and schema scripts are usually sent (JuliaDatabases#23). Postgres.execute_script(conn, sql) sends the string as one Query message and returns the command tag of each statement, discarding rows. The first server error is thrown after draining to ReadyForQuery, so the connection stays usable, and the transaction status is refreshed either way. COPY in a script is rejected: copy-in is aborted with CopyFail, copy-out is drained. The query logger reports it as :execute_script. DBInterface.execute and the internal execute_simple are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I went ahead and built this so #23 has something concrete to look at; think of it as a long comment on the issue that happens to compile. PormG's migrations kept running into the limitation, which was motivation enough.
I'm happy to change the name, the return value or the COPY behavior, or to close this if you prefer a different approach or would rather write it yourself.
DBInterface.executealways uses the extended protocol, so a string holding several statements fails, even without parameters:libpq runs the same string with
PQexec, which is how migration and schema scripts are usually sent.Postgres.execute_script(conn, sql)sendssqlas one simple-query message and returns the command tag of each statement, e.g.["CREATE TABLE", "COMMENT"]. Result rows are discarded;DBInterface.executeremains the way to run queries. It reuses the existing simple-query building blocks but has its own read loop, ascopy_inandcopy_outdo, soexecute_simpleand the transaction helpers are unchanged.server_in_transactionis refreshed from ReadyForQuery either way.COPY ... FROM STDINin a script is aborted with CopyFail and rejected with aPostgresInterfaceErrorpointing atcopy_from.COPY ... TO STDOUTis drained and rejected the same way as inexecute; because the simple protocol cannot abort a copy-out, the docstring says the rest of the script has already run by then.:execute_script.Choices I made that you may want differently: the name; returning only the tags; rejecting COPY rather than returning its tag.
Adds one public name,
execute_script. No runtime dependency changes. Closes #23.Validation:
;inside a literal and a dollar-quoted body; implicit-transaction rollback when a later statement fails;VACUUMrefused inside a multi-statement string (25001), as withPQexec;BEGIN/COMMITinside a script tracked; COPY rejected without desync.Pkg.test()with local Docker integration: 8846 checks pass on Julia 1.12.7 against PostgreSQL 14 (MD5), 16 and 18 (SCRAM), and 8819 on Julia 1.10.12; it also passes with-t 2(Linux x64).Additional checks against a real server
E'…'escapes, a trailing backslash in a standard string, quoted identifiers with"", nested$tag$bodies, nested block comments,U&'…', comments containing;) each returned exactly one tag per statement on PostgreSQL 16.cancel_query!from another task duringSELECT pg_sleep(5); SELECT 1raises 57014, and the connection stays usable.execute_script, with the same result as sending them through LibPQ'sPQexec.This PR was written with AI assistance (Claude Code) and reviewed by me before opening. The checks above were run as described.
🤖 Generated with Claude Code