I'm trying to learn databases in golang with postgresql by tutorials.
Although database exists, program gives output:
go run dbase.go
2017/01/02 20:43:07 pq: database "bookstore" does not exist
this is psql output:
deneme=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
bookstore | postgres | UTF8 | C | C |
deneme | postgres | UTF8 | C | C |
and this is the relevant part of go code:
const (
DB_USER = "postgres"
DB_PASSWORD = "root"
DB_NAME = "bookstore"
)
func main() {
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
if err != nil {
log.Fatal(err)
}
Also changing connection code to this gives the same output:
db, err := sql.Open("postgres", "postgres://postgres:root@localhost/bookstore?sslmode=disable")
Thanks;