15.10 - INTERVAL DAY TO SECOND Data Type - Teradata Database

Teradata Database SQL Data Types and Literals

prodname
Teradata Database
vrm_release
15.10
category
Programming Reference
featnum
B035-1143-151K

Identifies a field as an INTERVAL value defining a period of time in days, hours, minutes, and seconds.

where:

 

Syntax element …

Specifies …

precision

the permitted range of digits for DAY, ranging from one to four.

The default is two.

fractional_seconds_precision

the fractional precision for the values of SECOND.

The default is six.

attributes

appropriate data type, column storage, or column constraint attributes.

See “Core Data Type Attributes” on page 17 and “Storage and Constraint Attributes” on page 18 for specific information.

INTERVAL DAY TO SECOND is ANSI SQL:2011 compliant.

Conceptually, INTERVAL DAY TO SECOND is a record that has the following fields.

 

Field Name

Storage Format

Total Length

DAY

SMALLINT

10 bytes

HOUR

SMALLINT

MINUTE

SMALLINT

SECOND

INTEGER

INTERVAL DAY TO SECOND types are imported and exported in record and indicator modes as CHARACTER data using the client character set.

 

WHEN fractional_seconds_precision is …

THEN the type and format are …

0

Type:

CHARACTER(precision + 10)

Format:

'-d(precision) hh:mm:ss'

n

where n is 1 - 6

Type:

CHARACTER(precision + n + 11)

Format:

'-d(precision) hh:mm:ss.s(n)'

For example, for INTERVAL DAY (4) TO SECOND(3), the value might be something like '   125 12:27:31.125 '.

The DAY field has two leading blanks. The first is for a sign, which is not present for positive intervals. The second is to preserve the fixed size of the DAY field at four digits.

The range of values for INTERVAL DAY TO SECOND is as follows.

 

Type, Precision, and
Fractional Seconds Precision

Minimum Value

Maximum Value

INTERVAL DAY(1) TO SECOND(0)

-'9 23:59:59'

'9 23:59:59'

INTERVAL DAY(1) TO SECOND(1)

-'9 23:59:59.9'

'9 23:59:59.9'

INTERVAL DAY(1) TO SECOND(2)

-'9 23:59:59.99'

'9 23:59:59.99'

INTERVAL DAY(1) TO SECOND(3)

-'9 23:59:59.999'

'9 23:59:59.999'

INTERVAL DAY(1) TO SECOND(4)

-'9 23:59:59.9999'

'9 23:59:59.9999'

INTERVAL DAY(1) TO SECOND(5)

-'9 23:59:59.99999'

'9 23:59:59.99999'

INTERVAL DAY(1) TO SECOND(6)

-'9 23:59:59.999999'

'9 23:59:59.999999'

INTERVAL DAY(2) TO SECOND(0)

-'99 23:59:59'

'99 23:59:59'

INTERVAL DAY(2) TO SECOND(1)

-'99 23:59:59.9'

'99 23:59:59.9'

INTERVAL DAY(2) TO SECOND(2)

-'99 23:59:59.99'

'99 23:59:59.99'

INTERVAL DAY(2) TO SECOND(3)

-'99 23:59:59.999'

'99 23:59:59.999'

INTERVAL DAY(2) TO SECOND(4)

-'99 23:59:59.9999'

'99 23:59:59.9999'

INTERVAL DAY(2) TO SECOND(5)

-'99 23:59:59.99999'

'99 23:59:59.99999'

INTERVAL DAY(2) TO SECOND(6)

-'99 23:59:59.999999'

'99 23:59:59.999999'

INTERVAL DAY(3) TO SECOND(0)

-'999 23:59:59'

'999 23:59:59'

INTERVAL DAY(3) TO SECOND(1)

-'999 23:59:59.9'

'999 23:59:59.9'

INTERVAL DAY(3) TO SECOND(2)

-'999 23:59:59.99'

'999 23:59:59.99'

INTERVAL DAY(3) TO SECOND(3)

-'999 23:59:59.999'

'999 23:59:59.999'

INTERVAL DAY(3) TO SECOND(4)

-'999 23:59:59.9999'

'999 23:59:59.9999'

INTERVAL DAY(3) TO SECOND(5)

-'999 23:59:59.99999'

'999 23:59:59.99999'

INTERVAL DAY(3) TO SECOND(6)

-'999 23:59:59.999999'

'999 23:59:59.999999'

INTERVAL DAY(4) TO SECOND(0)

-'9999 23:59:59'

'9999 23:59:59'

INTERVAL DAY(4) TO SECOND(1)

-'9999 23:59:59.9'

'9999 23:59:59.9'

INTERVAL DAY(4) TO SECOND(2)

-'9999 23:59:59.99'

'9999 23:59:59.99'

INTERVAL DAY(4) TO SECOND(3)

-'9999 23:59:59.999'

'9999 23:59:59.999'

INTERVAL DAY(4) TO SECOND(4)

-'9999 23:59:59.9999'

'9999 23:59:59.9999'

INTERVAL DAY(4) TO SECOND(5)

-'9999 23:59:59.99999'

'9999 23:59:59.99999'

INTERVAL DAY(4) TO SECOND(6)

-'9999 23:59:59.999999'

'9999 23:59:59.999999'

Teradata Database performs implicit conversion from one Interval data type to another Interval type in some cases. You can also use CAST to explicitly convert one Interval type to another.

Conversions are possible only within the same INTERVAL family. For example, you may convert a YEAR interval to months, but not to days or hours.

For more information, see “Data Type Conversions” in SQL Functions, Operators, Expressions, and Predicates.

The following statement creates a table with an INTERVAL DAY TO SECOND column:

   CREATE TABLE TimeInfo 
     (Id INTEGER
     ,Offset INTERVAL DAY (4) TO SECOND (4));