In a Go program using database/sql, will any unclosed prepared queries be closed when I Close the Postgres DB I'm using?
I've cut this down to a very simple example that does not need the Prepare but still shows the question (I believe I could just pass query string to QueryRow and get an implicit Prepare, but leave it explicit here so I can ask my question):
import (
"database/sql"
)
// Store struct is the postgres
type Store struct {
pq *sql.DB
}
type Info struct {
ID string `json:"id"`
Name string `json:"name"`
}
func (s *Store) GetInfo(id string) Info {
defer s.pq.Close()
stmt, err := s.pq.Prepare(`
SELECT id, name
FROM info
WHERE id = $1 LIMIT 1
`)
if err != nil {
return Info{}
}
var res Info
_ = stmt.QueryRow(id).Scan(&res.ID, &res.Name)
return res
}