Created
March 11, 2012 15:00
-
-
Save notedit/2016729 to your computer and use it in GitHub Desktop.
go pg.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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