postgresql-simple-interval
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Simple.Interval

Synopsis

Documentation

data Interval Source #

This type represents a PostgreSQL interval. Intervals can have month, day, and microsecond components. Each component is bounded, so they are not arbitrary precision. For more information about intervals, consult the PostgreSQL documentation: https://www.postgresql.org/docs/17/datatype-datetime.html#DATATYPE-INTERVAL-INPUT.

Note that the time library provides several duration types that are not appropriate to use as PostgreSQL intervals:

  • NominalDiffTime: Does not handle days or months. Allows up to picosecond precision. Is not bounded.
  • CalendarDiffTime: Does not handle days. Embeds a NominalDiffTime. Is not bounded.
  • CalendarDiffDays: Does not handle seconds. Is not bounded.

WARNING: The PostgreSQL interval parser is broken in versions prior to 15. It is not possible to round trip all intervals through PostgreSQL on those versions. You should upgrade to at least PostgreSQL version 15. For more information, see this patch: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=e39f99046

Constructors

MkInterval 

Fields

Instances

Instances details
Show Interval Source # 
Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

Eq Interval Source # 
Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

PersistField Interval Source #

Behaves the same as the FromField and ToField instances.

Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

PersistFieldSql Interval Source #
SqlOther "interval"
Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

FromField Interval Source #

Uses parse. Ensures that the OID is intervalOid.

Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

ToField Interval Source #

Uses render. Always includes an interval prefix, like interval ....

Instance details

Defined in Database.PostgreSQL.Simple.Interval.Unstable

Methods

toField :: Interval -> Action #

zero :: Interval Source #

The empty interval, representing no time at all.

>>> zero
MkInterval {months = 0, days = 0, microseconds = 0}

fromMicroseconds :: Int64 -> Interval Source #

Creates an interval from a number of microseconds.

>>> fromMicroseconds 1
MkInterval {months = 0, days = 0, microseconds = 1}

fromMilliseconds :: Int64 -> Maybe Interval Source #

Creates an interval from a number of milliseconds. Returns Nothing if the interval would overflow.

>>> fromMilliseconds 1
Just (MkInterval {months = 0, days = 0, microseconds = 1000})
>>> fromMilliseconds 9223372036854776
Nothing

fromSeconds :: Int64 -> Maybe Interval Source #

Creates an interval from a number of seconds. Returns Nothing if the interval would overflow.

>>> fromSeconds 1
Just (MkInterval {months = 0, days = 0, microseconds = 1000000})
>>> fromSeconds 9223372036855
Nothing

fromMinutes :: Int64 -> Maybe Interval Source #

Creates an interval from a number of minutes. Returns Nothing if the interval would overflow.

>>> fromMinutes 1
Just (MkInterval {months = 0, days = 0, microseconds = 60000000})
>>> fromMinutes 153722867281
Nothing

fromHours :: Int64 -> Maybe Interval Source #

Creates an interval from a number of hours. Returns Nothing if the interval would overflow.

>>> fromHours 1
Just (MkInterval {months = 0, days = 0, microseconds = 3600000000})
>>> fromHours 2562047789
Nothing

fromDays :: Int32 -> Interval Source #

Creates an interval from a number of days.

>>> fromDays 1
MkInterval {months = 0, days = 1, microseconds = 0}

fromWeeks :: Int32 -> Maybe Interval Source #

Creates an interval from a number of weeks. Returns Nothing if the interval would overflow.

>>> fromWeeks 1
Just (MkInterval {months = 0, days = 7, microseconds = 0})
>>> fromWeeks 306783379
Nothing

fromMonths :: Int32 -> Interval Source #

Creates an interval from a number of months.

>>> fromMonths 1
MkInterval {months = 1, days = 0, microseconds = 0}

fromYears :: Int32 -> Maybe Interval Source #

Creates an interval from a number of years. Returns Nothing if the interval would overflow.

>>> fromYears 1
Just (MkInterval {months = 12, days = 0, microseconds = 0})
>>> fromYears 178956971
Nothing