Raj*_*ram 6 stored-procedures snowflake-cloud-data-platform
目前正在将数据从一个雪花表加载到雪花中的另一个表,在加载数据时还进行一些数据类型转换
但是,当出现任何错误时,我的加载就会失败。我需要捕获表中的错误行并继续加载,尽管发生任何错误。
我已尝试使用如下存储过程,但只能捕获错误信息:-请告诉我是否有任何方法可以在雪花中实现此目的。
CREATE OR REPLACE PROCEDURE LOAD_TABLE_A()
RETURNS varchar
NOT NULL
LANGUAGE javascript
AS
$$
var result;
var sql_command = "insert into TABLE A"
sql_command += " select"
sql_command += " migration_status,to_date(status_date,'ddmmyyyy') as status_date,"
sql_command += " to_time(status_time,'HH24MISS') as status_time,unique_unit_of_migration_number,reason,"
sql_command += " to_timestamp_ntz(current_timestamp) as insert_date_time"
sql_command += " from TABLE B"
sql_command += " where insert_date_time>(select max(insert_date_time) from TABLE A);"
try {
snowflake.execute({ sqlText: sql_command});
result = "Succeeded";
}
catch (err) {
result = "Failed";
snowflake.execute({
sqlText: `insert into mcs_error_log VALUES (?,?,?,?)`
,binds: [err.code, err.state, err.message, err.stackTraceTxt]
});
}
return result;
$$;
Run Code Online (Sandbox Code Playgroud)
小智 0
加载错误信息由 Snowflake 捕获,可以通过查询 COPY_HISTORY 表函数来访问。
https://docs.snowflake.net/manuals/sql-reference/functions/copy_history.html
在 COPY INTO 命令中,您可以使用参数决定如果一行或多行加载过程失败时如何继续处理文件ON_ERROR。
https://docs.snowflake.net/manuals/sql-reference/sql/copy-into-table.html#copy-options-copyoptions