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 IntervalsThere 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 {@link 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 {@link Field#add(Field)} and {@link Field#sub(Field)} Databases that havebeen 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
:
|
|
|
|