Skip to content

Instantly share code, notes, and snippets.

@dt
Created July 6, 2016 18:25
Show Gist options
  • Save dt/62b1f57f752216fedeefd1a380f1c484 to your computer and use it in GitHub Desktop.
Save dt/62b1f57f752216fedeefd1a380f1c484 to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
"log"
"time"
_ "github.com/lib/pq"
)
func handle(res interface{}, err error) {
if err != nil {
panic(err)
}
log.Println(res)
}
func main() {
db, err := sql.Open("postgres", "postgresql://root@localhost:26257/d?sslmode=disable")
if err != nil {
panic(err)
}
handle(db.Exec("DROP DATABASE IF EXISTS d"))
handle(db.Exec("CREATE DATABASE d"))
handle(db.Exec("DROP TABLE IF EXISTS t"))
handle(db.Exec("CREATE TABLE t (t timestamp, tz timestamp with time zone)"))
handle(db.Exec("INSERT INTO t VALUES ($1, $2)", time.Time{}, time.Time{}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment