Open
Description
Describe the issue
Unable to send multiple SQL commands in one simpleQuery
.
Vapor version
1.21.5
Operating system and version
macOS 15
Swift version
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10) Target: arm64-apple-macosx15.0
Steps to reproduce
let db: PostgresDatabase = ...
_ = try await db.simpleQuery("""
SELECT current_setting('application_name');
SELECT current_setting('something_else');
""").get()
Outcome
server: cannot insert multiple commands into a prepared statement (exec_parse_message)
Additional notes
Postgres documentation mentions that multiple SQL commands in one simple query is allowed:
Activity
[-]Unable to send multiple SQL commands in one SQL query[/-][+]Unable to send multiple SQL commands in one `simpleQuery`[/+]vzsg commentedon Aug 15, 2024
I think the
simpleQuery
method is named as such in a casual manner: it's "simple" simply because a String goes in and rows come out. That's unrelated to the wire message the doc page is about, and is actually implemented as a prepared statement behind the scenes...MahdiBM commentedon Aug 15, 2024
That's what I figured ...
Looks to me, too big of a coincidence that they have the same name, but I guess the best solution right now is to just add a new function supporting the definition in Postgres' wire protocol.
MahdiBM commentedon Aug 15, 2024
Or it's possible we can just change the implementation of the current function without any breaking behavior changes.
fabianfett commentedon Aug 21, 2024
simpleQuery
used to allow multiple commands, before the big internals rewrite, that landed in1.5.0
.simpleQuery
are not so simple if you think about them more.simpleQuery
s can have multiple selects in a single statement. How do you want to hand the rows to the user now? It would need to be an AsyncSequence of AsyncSequence of Rows... But you can only iterate the outer AsyncSequence if you have emptied the inner AsyncSequence and so forth and so forth.@MahdiBM Do you want to drive an API design for this? Once we have an API design, we can look into implementing the Simple Statement flow and fix this API short-comming.
Alternative for now: Deprecate
simpleQuery
. Wdyt?cc @gwynne
SimpleQuery
Handling #505