aws-lambdasnowflake-cloud-data-platformaws-api-gateway

Snowflake is returning date column as integer values to AWS API server


I have data in Snowflake table.
This table has a date column that has dates like '8888-12-31', and '2023-11-04' etc.
When the AWS API server is querying this table and the json response is returned, the values returned for this column are like '2527113', '19829' etc.
These returned integer doesn't even look like epoc time in seconds. When i tried to convert these integer to date using datetime.fromtimestamp().strftime('%Y-%m-%d') function, its all getting resolved to year 1970-01-01 which is incorrect.
what to do ?


Solution

  • I resolved this by casting the date column as string when extracting the value. Somehow the Snowflake is returning some garbage integer value for date fields rather than actual date.
    I modified the query used in API's lambda.
    Earlier it was

    select hc_id, mcid, ins_dt from db.table where hc_id='ABC123'
    

    Now I changed it to

    select hc_id, mcid, to_varchar(ins_dt::date, 'yyyy-mm-dd') as ins_dt from db.table where hc_id='ABC123'
    

    and now the value is getting extracted with proper values.