15.10 - INTERVAL YEAR TO MONTH 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 years and months.

where:

 

Syntax element …

Specifies …

precision

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

The default is two.

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 YEAR TO MONTH is ANSI SQL:2011 compliant.

Conceptually, INTERVAL YEAR TO MONTH is a record with two fields.

 

Field Name

Storage Format

Total Length

YEAR

SMALLINT

4 bytes

MONTH

SMALLINT

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

 

Type

Format

CHARACTER(precision + 4)

'-y(precision)-mm'

An example value for INTERVAL YEAR(3) TO MONTH is ' 013-11'.

The range of values for the INTERVAL YEAR TO MONTH is as follows.

 

Type and Precision

Minimum Value

Maximum Value

INTERVAL YEAR(1) TO MONTH

-'9-11'

'9-11'

INTERVAL YEAR(2) TO MONTH

-'99-11'

'99-11'

INTERVAL YEAR(3) TO MONTH

-'999-11'

'999-11'

INTERVAL YEAR(4) TO MONTH

-'9999-11'

'9999-11'

Note: Decimal values are not allowed for Interval data types except for second intervals.

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 YEAR TO MONTH column:

   CREATE TABLE TimeInfo 
     (Id INTEGER
     ,Offset INTERVAL YEAR (4) TO MONTH);