简体   繁体   English

在复制命令中使用 TO_DATE 函数时,雪花验证选项不返回失败的记录

[英]Snowflake Validate Option does not return Failed records When using TO_DATE function in Copy Command

I have used Copy Command as below:我使用了复制命令如下:

copy into test2 from @%test2 file_format = (format_name = 'CSV') on_error = 'CONTINUE';从@%test2 file_format = (format_name = 'CSV') on_error = 'CONTINUE' 复制到 test2;

My file contains some Character data in Number field ( for all records) so Copy result is LOAD_FAILED and I can get fail records using below query ( in this case all records are failed records):我的文件在 Number 字段中包含一些字符数据(对于所有记录),因此复制结果为 LOAD_FAILED,我可以使用以下查询获取失败记录(在这种情况下,所有记录都是失败记录):

select * from table(validate("TEST2", job_id=>'Corresponding JOB ID')); select * from table(validate("TEST2", job_id=>'Corresponding JOB ID'));

I also tried giving invalid dates and still got all bad records from above query.我还尝试给出无效日期,但仍然从上述查询中得到所有错误记录。

Now I tried Copy command as below: copy into test2(test1,test2) from (select $1,to_date($2,'YYYYDDD') from @%test2) file_format = (format_name = 'CSV') on_error = 'CONTINUE';现在我尝试复制命令如下: copy into test2(test1,test2) from (select $1,to_date($2,'YYYYDDD') from @%test2) file_format = (format_name = 'CSV') on_error = 'CONTINUE';

Copy result was again LOAD_FAILED but I do not get any fail record from below query now: select * from table(validate("TEST2", job_id=>'Corresponding JOB ID'));复制结果再次 LOAD_FAILED 但我现在没有从下面的查询中得到任何失败记录: select * from table(validate("TEST2", job_id=>'Corresponding JOB ID'));

does this work only for regular copy without any conversion function in Copy or there is any other reason?这是否仅适用于常规副本,而副本中没有任何转换功能,还是有其他原因?

Adding One more example after seeing response from Mike below: File data: 1,2018-1-34 2,2/3/2016 3,2020124在看到下面 Mike 的回复后,再添加一个示例:文件数据:1,2018-1-34 2,2/3/2016 3,2020124

table-> create table test2(test1 number,test2 date)表-> 创建表 test2(test1 编号,test2 日期)

copy into test2(test1,test2) from (select $1,to_date($2,'YYYYDD') from @%test2) file_format = (format_name = 'CSV') on_error = 'CONTINUE';复制到 test2(test1,test2) from (select $1,to_date($2,'YYYYDD') from @%test2) file_format = (format_name = 'CSV') on_error = 'CONTINUE';

first and third record are available in Validate query.第一条和第三条记录在验证查询中可用。 Only the second record in not present in this case.在这种情况下,只有第二条记录不存在。 its weird.有点奇怪。 ( all three records failed in copy) . (所有三个记录都无法复制)。

As Mike said below in comments Validate does not work with transform data in copy but why does it provide two records in that case.正如迈克在下面的评论中所说,验证不适用于复制中的转换数据,但为什么在这种情况下它提供两条记录。 it should wither not provide anything at all or all of them?它应该不提供任何东西或全部吗?

Per the documentation, since you are transforming the data during the COPY INTO, the VALIDATE function will no longer work:根据文档,由于您在 COPY INTO 期间转换数据,因此 VALIDATE 函数将不再起作用:

This function does not support COPY INTO statements that transform data during a load.此函数不支持在加载期间转换数据的 COPY INTO 语句。

https://docs.snowflake.com/en/sql-reference/functions/validate.html#usage-notes https://docs.snowflake.com/en/sql-reference/functions/validate.html#usage-notes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM