TRUNC (date) UDF

Description

The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. (Oracle TRUNC(date) SQL Language Referencearrow-up-right)

TRUNC(date [, fmt ])

Oracle TRUNC and Snowflake TRUNC function with date arguments have some functional differences.

TRUNC_UDF helper will be added to handle the following cases:

1. The format is not supported by Snowflake.

2. The format exists in Snowflake but works differently.

3. The tool cannot determine the datatype of the first argument.

4. The format is provided as a column or expression and not as a literal.

Please refer to EWI3083 arrow-up-rightand EWI3117 arrow-up-rightfor examples of each case.

Custom UDF overloads

TRUNC_UDF(date)

It applies an explicit DATE castarrow-up-right to the input Timestamp.

Parameters

  1. INPUT: The Timestamp with Time Zone (TIMESTAMP_LTZarrow-up-right) that needs to be truncated.

circle-exclamation

Oracle

Snowflake

TRUNC_UDF(date, fmt)

Manually creates a new date using DATE_FROM_PARTS() functionarrow-up-right, depending on the format category used.

Parameters

  1. DATE_TO_TRUNC: The Timestamp with Time Zone (TIMESTAMP_LTZarrow-up-right) that needs to be truncated.

  2. DATE_FMT: The date format as a VARCHAR. Same formats that are supportedarrow-up-right in Oracle.

circle-exclamation

TRUNC format scenarios

circle-exclamation

1. Natively supported formats

Oracle

Snowflake

2. Formats mapped to another format

Oracle

Snowflake

3. Day formats

circle-info

Please check MSCEWI3117 arrow-up-rightdocumentation

Oracle

Snowflake

4. Unsupported formats

circle-info

Please check MSCEWI3083 arrow-up-rightdocumentation

Oracle

Snowflake

Known Issues

1. Oracle DATE contains TIMESTAMP

Take into consideration that Oracle DATE contains an empty TIMESTAMP (00:00:00.000), while Snowflake DATE does not. SnowConvert allows transforming DATE to TIMESTAMP with the SysdateAsCurrentTimestamparrow-up-right flag.

  1. MSCEWI3083arrow-up-right: Unhandled arguments for the TRUNC function.

  2. MSCEWI3117arrow-up-right: Day format works differently between Oracle and Snowflake.

Last updated

Was this helpful?