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

Unable to send multiple SQL commands in one simpleQuery #499

Open
MahdiBM opened this issue Aug 15, 2024 · 4 comments · May be fixed by #505
Open

Unable to send multiple SQL commands in one simpleQuery #499

MahdiBM opened this issue Aug 15, 2024 · 4 comments · May be fixed by #505
Labels
bug Something isn't working

Comments

@MahdiBM
Copy link
Contributor

MahdiBM commented Aug 15, 2024

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:

A simple query cycle is initiated by the frontend sending a Query message to the backend. The message includes an SQL command (or commands) expressed as a text string.

@MahdiBM MahdiBM added the bug Something isn't working label Aug 15, 2024
@MahdiBM MahdiBM changed the title Unable to send multiple SQL commands in one SQL query Unable to send multiple SQL commands in one simpleQuery Aug 15, 2024
@vzsg
Copy link
Member

vzsg commented 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
Copy link
Contributor Author

MahdiBM commented 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
Copy link
Contributor Author

MahdiBM commented Aug 15, 2024

Or it's possible we can just change the implementation of the current function without any breaking behavior changes.

@fabianfett
Copy link
Collaborator

simpleQuery used to allow multiple commands, before the big internals rewrite, that landed in 1.5.0. simpleQuery are not so simple if you think about them more.

simpleQuerys 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

@MahdiBM MahdiBM linked a pull request Aug 26, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants