Answer the question
In order to leave comments, you need to log in
What is the error when fetching from a Postgresql database?
Below is the program code
package main
import (
"database/sql"
_ "github.com/lib/pq"
"log"
"fmt"
)
const (
DB_USER = "postgres"
DB_PASSWORD = ""
DB_NAME = "test"
)
type User struct {
id int
}
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)
defer db.Close()
if err != nil {
log.Fatal(err)
}
rows, err := db.Query(" SELECT * FROM users ")
defer rows.Close()
if err != nil {
log.Fatal(err)
}else{
if(rows.Next()){
usr := new (User)
err := rows.Scan(&usr.id)
if err != nil {
log.Fatal(err)
}
fmt.Println(usr.id)
}
}
}
pq: relation "users" does not exist
exit status 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question