THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Travis J Parker 03ffc38323 commit to test code review 3 years ago
LICENSE BSD3 4 years ago
README.markdown README note about the 30 day assumption 3 years ago
duration.go don't include months in serialized forms 3 years ago
duration_test.go don't include months in serialized forms 3 years ago
interval.go don't include months in serialized forms 3 years ago
interval_test.go don't include months in serialized forms 3 years ago
parse.go tests and bugfixes 4 years ago
parse_test.go commit to test code review 3 years ago

README.markdown

pqinterval

Scan targets for PostgreSQL's interval type.

The Interval type supports the full range of PostgreSQL intervals. Any database interval should successfully Scan() into a pqinterval.Interval.

Example:

var ival pqinterval.Interval

err := conn.QueryRow("SELECT '4 days'::INTERVAL").Scan(&ival)
if err != nil {
    log.Fatal(err)
}

fmt.Println(ival.Hours())

The Duration type is an alias of time.Duration, but which supports scanning from PostgreSQL intervals (potentially failing with ErrTooBig).

Example:

var since time.Duration
d := (*pqinterval.Duration)(&since)

err = conn.QueryRow("SELECT '2 days'::INTERVAL").Scan(d)
if err != nil {
    log.Fatal(err)
}

fmt.Println(since)

One caveat to be aware of: while PostgreSQL intervals are capable of modeling a number of "months", the Interval and Duration types here are not. Any time they scan an "x months" interval they will assume 30 days in a month. PostgreSQL avoids this ambiguity however when subtracting distant timestamps, by providing a large number of days rather than breaking them down into months.