-
Notifications
You must be signed in to change notification settings - Fork 937
Closed
Description
After I upgrade lib/pq from v1.10.7 to v1.10.8. It's panic every query command with message
runtime error: index out of range [0] with length 0
After investigate I found that if .pgpass contains empty line, It'll error.
Step to reproduce
- Create
~/.pgpasswith this content
localhost:5432:*:postgres:password
localhost:5432:*:user:password
- Set
.pgpasspermission
$ chmod 600 ~/.pgpass
- Run this Go code
package main
import (
"database/sql"
"log"
_ "github.com/lib/pq"
)
func main() {
db, err := sql.Open("postgres", "postgres://postgres@localhost/postgres?sslmode=disable")
if err != nil {
log.Fatalf("Error opening database: %v", err)
}
defer db.Close()
var n int
err = db.QueryRow(`select 1`).Scan(&n)
if err != nil {
log.Fatalf("Error querying database: %v", err)
}
log.Printf("n=%d", n)
}go run .
2023/04/16 15:53:49 Error querying database: runtime error: index out of range [0] with length 0
exit status 1Metadata
Metadata
Assignees
Labels
No labels