This package is now deprecated. The up to date version is at github.com/lib/pq.
go get github.com/bmizerany/pq
http://go.pkgdoc.org/github.com/bmizerany/pq
package main
import (
_ "github.com/bmizerany/pq"
"database/sql"
)
func main() {
db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
// ...
}
Connection String Parameters
These are a subset of the libpq connection parameters. In addition, a number of the environment variables supported by libpq are also supported. Just like libpq, these have lower precedence than explicitly provided connection parameters.
See http://www.postgresql.org/docs/9.1/static/libpq-connect.html.
dbname
- The name of the database to connect touser
- The user to sign in aspassword
- The user's passwordhost
- The host to connect to. Values that start with /
are for unix domain sockets. (default is localhost
)port
- The port to bind to. (default is 5432
)sslmode
- Whether or not to use SSL (default is require
, this is not the default for libpq)disable
- No SSLrequire
- Always SSL (skip verification)verify-full
- Always SSL (require verification)See http://golang.org/pkg/database/sql to learn how to use with pq
through the database/sql
package.
go test
is used for testing. A running PostgreSQL server is
required, with the ability to log in. The default database to connect
to test with is "pqgotest," but it can be overridden using environment
variables.
Example:
PGHOST=/var/run/postgresql go test pq
database/sql
time.Time
correctly (i.e. timestamp[tz]
, time[tz]
, date
)bytea
)LISTEN
/NOTIFY
hstore
sugar (i.e. handling hstore in rows.Scan
)Some of these contributors are from the original library bmizerany/pq.go
whose
code still exists in here.