snowflake-cloud-data-platformsnowflake-schema

How to insert data in the form of dd/mm/yyyy hh:mm in snowflake


I have the data in the source system as 'dd/mm/yyyy hh:mm' so i thought of using datetime in snowflake, but the documentation says that the format is 'dd/mm/yyyy hh:mm:ss' so it throws me an error stating that

Timestamp '01/02/2009 04:53' is not recognized

so in this scenario what should i do in order to store the data in snowflake if the source system is in this format.

Possible solutions that i have found out is:

The Schema Looks like this:


Solution

  • You may change your timestamp input format for your session when loading data:

    create or replace table test_table (v datetime);
    
    alter session set TIMESTAMP_INPUT_FORMAT='DD/MM/YYYY HH24:MI';
    
    insert into test_table values ('01/02/2009 04:53'); -- works
    

    TIMESTAMP_INPUT_FORMAT https://docs.snowflake.com/en/sql-reference/parameters.html#label-timestamp-input-format

    Or you can use transformation with your copy command:

    https://docs.snowflake.com/en/user-guide/data-load-transform.html#convert-data-types-during-a-load