To copy parquet file from Azure Blob Storage into Snowflake table, I have created a stored procedure, but I don't know how to convert timestamp in source data to date.
CREATE OR REPLACE PROCEDURE PROC_IMPORT_COPY_DATA(year varchar,month varchar,day varchar)
returns varchar
LANGUAGE sql
AS
$$
BEGIN
let delete_query varchar:= 'delete from PRD_RAW_DATA.PUBLIC.SAMPLE_DATA where load_date = substr(to_char(CURRENT_DATE()),1,4) || substr(to_char(CURRENT_DATE()),6,2) || substr(to_char(CURRENT_DATE()),9,2)';
execute immediate delete_query;
let uri varchar := concat(
'select
$1:COMPANY_CODE,
$1:STORE_CODE,
$1:JAN_CODE,
$1:PERIOD,
$1:QUANTITY,
$1:AMOUNT,
$1:GROSS_PROFIT,
$1:SELLING_PRICE,
$1:SALE_QUANTITY,
$1:SALE_AMOUNT,
$1:SALE_GROSS_PROFIT,
$1:SALE_PRICE,
$1:NUMBER_OF_DEALERS,
$1:NUMBER_OF_VISITORS,
$1:LOAD_DATE
FROM @SYNAPSE_STAGE_PRD/delta/sample_data'
,'/year='
, :year
,'/month='
, :month
,'/day='
, :day
);
let copy_query varchar := concat('copy into PRD_RAW_DATA.PUBLIC.SAMPLE_DATA from '
,'('
,uri
,'(file_format => my_parquet_format, pattern => \'.*.parquet\') t'
,') force=TRUE'
);
execute immediate copy_query;
return(copy_query);
END;
$$;
This is error message; Uncaught exception of type 'STATEMENT_ERROR' on line 77 at position 4: Failed to cast variant value "2022-08-17 00:00:00.000" to DATE
Do you know the solution to this? Any help would be appriciated. Thank you.
You can cast a timestamp to date if needed, like this:
select '2022-08-17 00:00:00.000'::date;
gives me:
2022-08-17
In your case I am not sure which is the column that gives that error but if I would take one that looks like a timestamp:
$1:LOAD_DATE
you could do:
$1:LOAD_DATE::date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.