Closed linlexing closed 4 years ago
When querying an empty table, 'rows.Columns' has no value,but github.com/lib/pq returns the correct result
github.com/lib/pq
package main import ( "database/sql" "github.com/davecgh/go-spew/spew" _ "github.com/jackc/pgx/v4/stdlib" _ "github.com/lib/pq" ) const dburl = "postgres://xxx:xxx@localhost:5432/postgres?sslmode=disable" func main() { func() { db, err := sql.Open("pgx", dburl) if err != nil { panic(err) } rows, err := db.Query("select 1 where 1=2") if err != nil { panic(err) } defer rows.Close() cols, err := rows.Columns() if err != nil { panic(err) } println("pgx columns:") spew.Dump(cols) }() func() { db, err := sql.Open("postgres", dburl) if err != nil { panic(err) } rows, err := db.Query("select 1 where 1=2") if err != nil { panic(err) } defer rows.Close() cols, err := rows.Columns() if err != nil { panic(err) } println("pq columns:") spew.Dump(cols) }() }
output:
pgx columns: ([]string) { } pq columns: ([]string) (len=1 cap=1) { (string) (len=8) "?column?" }
Sorry, I misplaced it
When querying an empty table, 'rows.Columns' has no value,but
github.com/lib/pq
returns the correct resultoutput: