Skip to content

Instantly share code, notes, and snippets.

@notedit
Created March 11, 2012 15:00
Show Gist options
  • Save notedit/2016729 to your computer and use it in GitHub Desktop.
Save notedit/2016729 to your computer and use it in GitHub Desktop.
go pg.go
package main
import (
"log"
"database/sql"
_ "github.com/bmizerany/pq.go"
)
func main() {
db,err := sql.Open("postgres","postgres://user:password@locahost:5432/database")
if err != nil {
log.Fatal(err)
}
rows,err := db.Query("SELECT length($1) AS foo","hello")
if err != nil {
log.Print(err)
}
var length int
for rows.Next() {
err := rows.Scan(&length)
if err != nil {
log.Print(err)
break
}
log.Printf("length = %d",length)
}
if rows.Err() != nil {
log.Print(rows.Err())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment