lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
9.11k stars 911 forks source link

Inconsistent behaviour of rows.NextResultSet() between lib/pg and go-sql-driver/mysql #828

Open ghost opened 5 years ago

ghost commented 5 years ago

Calling NextResultSet() on rows returned by

rows, err := db.QueryContext(ctx, "select somecol from sometable")

behaves inconsistent between lib/pq and go-sql-driver/mysql. While it is true for pq, it is false for mysql. This gists shows complete code that demonstrates this behaviour:

https://gist.github.com/lutzhorn/1aa7de538d1edd0b3904799b5bb972fd

The maintainers of mysql claim on the go-nuts mailinglist that returning false ist correct in this scenario.

What is the correct behaviour?

methane commented 5 years ago

Ref: https://groups.google.com/d/msg/golang-nuts/WMw_vsiFpvU/uwvCJus8DwAJ

This is the subthread about this difference.

methane commented 5 years ago

Another reference is this: https://golang.org/pkg/database/sql/driver/#RowsNextResultSet

        // HasNextResultSet is called at the end of the current result set and
        // reports whether there is another result set after the current one.
        HasNextResultSet() bool

        // NextResultSet advances the driver to the next result set even
        // if there are remaining rows in the current result set.
        //
        // NextResultSet should return io.EOF when there are no more result sets.
        NextResultSet() error

Maybe, lib/pq doesn't have full implementation of NextResultSet? It can not "skip remaining rows in the current result set."