Skip to content

Unable to send multiple SQL commands in one simpleQuery #499

Open
@MahdiBM

Description

@MahdiBM
Contributor

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.

Activity

changed the title [-]Unable to send multiple SQL commands in one SQL query[/-] [+]Unable to send multiple SQL commands in one `simpleQuery`[/+] on Aug 15, 2024
vzsg

vzsg commented on Aug 15, 2024

@vzsg
Member

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

MahdiBM commented on Aug 15, 2024

@MahdiBM
ContributorAuthor

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

MahdiBM commented on Aug 15, 2024

@MahdiBM
ContributorAuthor

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

fabianfett

fabianfett commented on Aug 21, 2024

@fabianfett
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

linked a pull request that will close this issue on Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @vzsg@fabianfett@MahdiBM

      Issue actions

        Unable to send multiple SQL commands in one `simpleQuery` · Issue #499 · vapor/postgres-nio