Skip to content
This repository
branch: master

Support timestamp without tz, redux

This time, some more effort has been paid to testing on an older Go
version, 1.0.2, and carefully preserving the old hacks to make time
parsing work with those older versions with a less useful time.Parse.
It has also been tested on Go 1.0.3.

This just lets the Go time package use its default behavior when one
is left without time offset information.  Hope it is a behavior people
want.

The main change here is pushing down the column type into the parsing
function, as Go's time parsing can't deal with data that only has the
fractional-hour timezone offset when such a fraction exists
(e.g. "-07" for "-07:00", but "-7:30" necessarily retaining its
precision).  This old hack could not be applied unconditionally (it is
wrong when the timestamp has no time zone offset suffix), so this
information lets a correct decision be made.

Clearly, this approach also can't handle the Postgres datestyle
parameter, but that's a fight to pick some other time.

As a target of opportunity, move the 'oid' type to 'types.go', since
for now all oids I know of handled by the program are type oids.  This
causes 'go fmt' to go a little nuts and rewrite the long but boring
file.

Signed-off-by: Daniel Farina <daniel@fdr.io>
latest commit 284a1d41dc
Daniel Farina fdr authored
Octocat-spinner-32 .gitignore Add Vim temporary and backup files to .gitignore.
Octocat-spinner-32 LICENSE.md LICENCE - fixes #40
Octocat-spinner-32 README.md Credit Kamil Kisiel
Octocat-spinner-32 buf.go Add parameter type sensitivity to type encoding
Octocat-spinner-32 conn.go Support timestamp without tz, redux
Octocat-spinner-32 conn_test.go Add failing test for error checking on 64 bits int
Octocat-spinner-32 encode.go Support timestamp without tz, redux
Octocat-spinner-32 encode_test.go Support timestamp without tz, redux
Octocat-spinner-32 error.go Add recover function that will report the PG reason.
Octocat-spinner-32 types.go Support timestamp without tz, redux
Octocat-spinner-32 url.go functional accrue for ParseURL
Octocat-spinner-32 url_test.go refactor url parsing
README.md

pq - A pure Go postgres driver for Go's database/sql package

Install

go get github.com/bmizerany/pq

Docs

http://go.pkgdoc.org/github.com/bmizerany/pq

Use

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 to
  • user - The user to sign in as
  • password - The user's password
  • host - 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) Valid values are:
    • disable - No SSL
    • require - 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.

Tests

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

Features

  • SSL
  • Handles bad connections for database/sql
  • Scan time.Time correctly (i.e. timestamp[tz], time[tz], date)
  • Scan binary blobs correctly (i.e. bytea)
  • pq.ParseURL for converting urls to connection strings for sql.Open.
  • Many libpq compatible environment variables
  • Unix socket support

Future / Things you can help with

  • Notifications: LISTEN/NOTIFY
  • hstore sugar (i.e. handling hstore in rows.Scan)

Thank you (alphabetical)

Some of these contributors are from the original library bmizerany/pq.go whose code still exists in here.

  • Andy Balholm (andybalholm)
  • Ben Berkert (benburkert)
  • Bjørn Madsen (aeons)
  • Blake Gentry (bgentry)
  • Brad Fitzpatrick (bradfitz)
  • Daniel Farina (fdr)
  • Everyone at The Go Team
  • Federico Romero (federomero)
  • Heroku (heroku)
  • John Gallagher (jgallagher)
  • Kamil Kisiel (kisielk)
  • Keith Rarick (kr)
  • Marc Brinkmann (mbr)
  • Martin Olsen (martinolsen)
  • Mike Lewis (mikelikespie)
  • Ryan Smith (ryandotsmith)
  • Samuel Stauffer (samuel)
  • notedit (notedit)
Something went wrong with that request. Please try again.