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 access reader from MultiResultReader because it is not exposed to client #1512

Open
mansapabbaraju opened this issue Feb 16, 2023 · 1 comment

Comments

@mansapabbaraju
Copy link

mansapabbaraju commented Feb 16, 2023

Query() returns a Rows interface (implemented by baseRows in conn.go), and rows.Next() is pointing to the first ResultReader.
every consequent call to rows.Next() will return the next row of this first ResultResult

if running multiple queries in a single query, results of multi query are stored in MultiResultReader
However, this MultiResultReader is never exposed to the client, so it looks like client cannot call NextResultReader() and obtain results from next reader.

Even though in v5, Rows interface has a Conn(). that exposes the internal PgConn which in turn has the MultiResultReader, this is still private for the client (application code)

running multi statements usingQueryExecModeSimpleProtocol

How can one access all results from MultiResultReader?

@jackc
Copy link
Owner

jackc commented Feb 16, 2023

If your application knows what queries it is sending it should use a batch instead of Query. Query is generally intended for running a single query. As I'm guessing you discovered multiple queries only works with QueryExecModeSimpleProtocol. And that is more like "it happens to work", rather than being an encouraged use case.

But if your program doesn't know what it is running and it still needs to iterate over the results, then you need to go down to the underlying pgconn.Conn and call Exec. You can either directly handle the results (since you don't know what queries were run you probably just want the values rather than scanning into anything) or you can use RowsFromResultReader to get a Rows and handle it with that.

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