INTERVAL YEAR TO MONTH Data Type

Description

INTERVAL YEAR TO MONTH stores a period of time using the YEAR and MONTH datetime fields. There is no equivalent in Snowflake so it is transformed to Varchar (Oracle SQL Language Reference INTERVAL YEAR TO MONTH Data Type)

There is no equivalent for this data type in Snowflake, it is currently transformed to VARCHAR.

INTERVAL YEAR [(year_precision)] TO MONTH

Sample Source Patterns

Interval Year To Month in Create Table

Oracle

CREATE TABLE interval_year_to_month_table
(
	interval_year_col1 interval year to month,
	interval_year_col2 interval year(4) to month
);

INSERT INTO interval_year_to_month_table(interval_year_col1) VALUES ( INTERVAL '1-2' YEAR TO MONTH ); 
INSERT INTO interval_year_to_month_table(interval_year_col2) VALUES ( INTERVAL '1000-11' YEAR(4) TO MONTH );

Snowflake

-- SELECT INTERVAL '1-5' YEAR TO MONTH FROM DUAL;
CREATE OR REPLACE TABLE PUBLIC.interval_year_to_month_table (
interval_year_col1 VARCHAR(20) /*** MSC-WARNING - MSCEWI1036 - INTERVAL year to month DATA TYPE CONVERTED TO VARCHAR ***/,
interval_year_col2 VARCHAR(20) /*** MSC-WARNING - MSCEWI1036 - INTERVAL year(4) to month DATA TYPE CONVERTED TO VARCHAR ***/);

INSERT INTO PUBLIC.interval_year_to_month_table(interval_year_col1) VALUES ('1y, 2m' );

INSERT INTO PUBLIC.interval_year_to_month_table(interval_year_col2) VALUES ('1000y, 11m' );

The Interval value is transformed to a supported Snowflake format and then inserted as text inside the column. Since Snowflake does not support Interval as a data type, it is only supported in arithmetic operations. In order to use the value, it needs to be extracted and used as an Interval constant (if possible).

Original Oracle value: INTERVAL '1-2' YEAR TO MONTH

Value stored in Snowflake column: '1y, 2m'

Value as Snowflake Interval constant: INTERVAL '1y, 2m'

Retrieving data from an Interval Year To Month column

Oracle

SELECT * FROM interval_year_to_month_table;

Snowflake

SELECT * FROM PUBLIC.interval_year_to_month_table;

Known Issues

1. Only arithmetic operations are supported

Snowflake Intervals have several limitations. Only arithmetic operations between DATE or TIMESTAMP and Interval Constants are supported, every other scenario is not supported. For more information please review MSCEWI3095 and MSCEWI3096.

  1. MSCEWI1036: Data type converted to another data type.

  2. MSCEWI3095: Operation Between Interval and Date Type not Supported.

  3. MSCEWI3096: Interval Literal Not Supported In Current Scenario.

Last updated