Top Description Methods
org.jooq.types

public Interface Interval

extends Serializable
Known Direct Implementers
org.jooq.types.YearToMonth, org.jooq.types.YearToSecond, org.jooq.types.DayToSecond
Imports
java.io.Serializable, java.time.Duration, .YearMonth, org.jooq.Field, .SQLDialect

A substitute for JDBC's missing java.sql.Interval data type.

JDBC lacks an important data type that is present in most SQL databases: INTERVAL. The SQL:2008 standard states that there are two types of intervals:

4.6.3 Intervals

There are two classes of intervals. One class, called year-month intervals, has an express or implied datetime precision that includes no fields other than YEAR and MONTH, though not both are required. The other class, called day-time intervals, has an express or implied interval precision that can include any fields other than YEAR or MONTH.

INTERVAL can be combined with date time data types according to the following operation table:

Operand 1 Operator Operand 2 Result Type
Datetime – Datetime Interval
Datetime + or – Interval Datetime
Interval + Datetime Datetime
Interval + or – Interval Interval
Interval * or / Numeric Interval
Numeric * Interval Interval

Interval implementations can be expected to also also extend Number.

Note: only a few databases actually support this data type on its own. You can still use it for date time arithmetic in other databases, though, through Field#add(Field) and Field#sub(Field) Databases that have been observed to natively support INTERVAL data types are:

These dialects have been observed to partially support INTERVAL data types in date time arithmetic functions, such as TIMESTAMPADD, and TIMESTAMPDIFF:

Author
Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public Interval
abs()

Get the absolute value of the interval (set its sign to positive)

public byte
public double
public float
public int

Returns:

1 for positive or zero, -1 for negative
getSign
()

The sign of the interval

public int
public long
public Interval
neg()

Negate the interval (change its sign)

public short
public Duration
toDuration()

Get a duration representation of this interval.

Method Detail

absback to summary
public Interval abs()

Get the absolute value of the interval (set its sign to positive)

byteValueback to summary
public byte byteValue()
See Also
Number#byteValue()
doubleValueback to summary
public double doubleValue()
See Also
Number#doubleValue()
floatValueback to summary
public float floatValue()
See Also
Number#floatValue()
getSignback to summary
public int getSign()

The sign of the interval

Returns:int

1 for positive or zero, -1 for negative

intValueback to summary
public int intValue()
See Also
Number#intValue()
longValueback to summary
public long longValue()
See Also
Number#longValue()
negback to summary
public Interval neg()

Negate the interval (change its sign)

shortValueback to summary
public short shortValue()
See Also
Number#shortValue()
toDurationback to summary
public Duration toDuration()

Get a duration representation of this interval.

There is an obvious Duration representation for DayToSecond intervals. If the interval contains YearMonth information, then the corresponding duration will use:

  • 1 year = 365.25 days
  • 1 month = 30 days

This corresponds to PostgreSQL's EXTRACT(EPOCH FROM my_interval) behaviour.