Categories:

Semi-structured and structured data functions (Cast)

AS_TIMESTAMP_*¶

Casts a VARIANT value to the respective TIMESTAMP value:

  • AS_TIMESTAMP_LTZ (value with local time zone)

  • AS_TIMESTAMP_NTZ (value with no time zone)

  • AS_TIMESTAMP_TZ (value with time zone)

See also:

AS_<object_type> , AS_DATE , AS_TIME

Syntax¶

AS_TIMESTAMP_LTZ( <variant_expr> )

AS_TIMESTAMP_NTZ( <variant_expr> )

AS_TIMESTAMP_TZ( <variant_expr> )
Copy

Arguments¶

variant_expr

An expression that evaluates to a value of type VARIANT.

Examples¶

This shows how to use the function:

Create a table and data:

CREATE TABLE multiple_types (
    binary1 VARIANT,
    date1 VARIANT,
    decimal1 VARIANT,
    time1 VARIANT,
    timestamp1 VARIANT
    );
INSERT INTO multiple_types 
     (binary1, date1, decimal1, time1, timestamp1)
   SELECT 
     TO_VARIANT(TO_BINARY('F0A5')),
     TO_VARIANT(TO_DATE('2018-10-10')), 
     TO_VARIANT(TO_DECIMAL(1.23, 6, 3)),
     TO_VARIANT(TO_TIME('12:34:56')),
     TO_VARIANT(TO_TIMESTAMP_NTZ('2018-10-10 12:34:56'))
     ;
Copy

Now run the query:

SELECT AS_TIMESTAMP_NTZ(timestamp1) AS "Timestamp" FROM multiple_types;
Copy

Output:

+-------------------------+
| Timestamp               |
|-------------------------|
| 2018-10-10 12:34:56.000 |
+-------------------------+
Copy