in my code problem solved by adding sslmode=disable in sql.Open ... 

On Monday, August 24, 2015 at 7:43:52 PM UTC+4, Eva Yuen wrote:
>
> I'm trying to get data out of postgres with golang. I keep getting this 
> pointer error. With reflect I have checked the database has been connected 
> properly. Could anybody offer any advice on how to deal with this error 
>
>
> panic: runtime error: invalid memory address or nil pointer dereference 
> panic: 
> runtime error: invalid memory address or nil pointer dereference
> [signal 0xb code=0x1 addr=0x20 pc=0x4a0041]
>
> goroutine 1 [running]:
> database/sql.(*Rows).Close(0x0, 0x0, 0x0)
> /home/syuan/.gvm/gos/go1.4/src/database/sql/sql.go:1659 +0x31
> database/sql.(*Rows).Next(0x0, 0x1)
> /home/syuan/.gvm/gos/go1.4/src/database/sql/sql.go:1586 +0x25
> main.getpsql()
> /home/syuan/src-git/blue-prometheus/examples/postgres/main.go:40 +0x41e
> main.main()
> /home/syuan/src-git/blue-prometheus/examples/postgres/main.go:59 +0x1b
>
> goroutine 5 [chan receive]:
> database/sql.(*DB).connectionOpener(0xc208036000)
> /home/syuan/.gvm/gos/go1.4/src/database/sql/sql.go:589 +0x4c
> created by database/sql.Open
> /home/syuan/.gvm/gos/go1.4/src/database/sql/sql.go:452 +0x31c
>
> goroutine 17 [syscall, locked to thread]:
> runtime.goexit()
> /home/syuan/.gvm/gos/go1.4/src/runtime/asm_amd64.s:2232 +0x1
> exit status 2
>
>
>
> code is here :
>
>
>
> package main
>
> import (
>         "log"
>         "fmt"
>         "reflect"
>         _ "github.com/lib/pq"
>         "database/sql"
> )
>
> func getpsql() {
>         fmt.Println(sql.Drivers())
>         db, err := sql.Open("postgres","user=blue dbname=blue 
> password=blue sslmode=disable")
>         if err !=nil {
>                 log.Fatal(err)
>         }
>         err = db.Ping()
>         if err != nil {
>                 panic(err.Error())
>         }
>         rows, err :=db.Query("select * from napkin_stats limit 3")
>         fmt.Println(reflect.TypeOf(rows))
>         defer rows.Close()
>         for rows.Next() {
>                 var counter int
>         if err = rows.Scan(&counter);err != nil {
>                 panic(err)
>         }
>         }
> }
>
>
> func main() {
>         getpsql()
>
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to