简体   繁体   English

COPY ... FROM LOCAL 不会在控制台上输出错误

[英]COPY ... FROM LOCAL does not output error on console

COPY .. FROM LOCAL does not output error on console. COPY .. FROM LOCAL不会在控制台上输出错误。 For example:例如:

create table test (col1 INT);

and I have a file ( abc.data ) containing data to insert to the table test as below我有一个文件( abc.data ),其中包含要插入到表test中的数据,如下所示

1237232632624232
111
222

I used the command as below to insert data into table我使用如下命令将数据插入表中

COPY test from local 'abc.data';

I expect it outputs error (overflow) on console.我希望它在控制台上输出错误(溢出)。 However, it does not.然而,事实并非如此。 I workarounded by using EXCEPTIONS to output the error to file.我通过使用EXCEPTIONS将错误输出到文件来解决。

How do you know the way to output the error on console?你怎么知道在控制台上输出错误的方式? Thanks in advance.提前致谢。

By default, Vertica doesn't fail COPY command on every bad row.默认情况下,Vertica 不会在每个坏行上执行COPY命令。 Instead, It writes the errors and the bad rows to files in a directory called CopyErrorLogs located under Vertica's catalog path.相反,它将错误和坏行CopyErrorLogs位于 Vertica 目录路径下名为CopyErrorLogs的目录中的文件。

You can choose another location for those error files using EXCEPTIONS and REJECTED DATA options (like you did).您可以使用EXCEPTIONSREJECTED DATA选项(就像您所做的那样)为这些错误文件选择另一个位置。

Or, which may be more convenient, write the errors and bad data into a table:或者,可能更方便,将错误和错误数据写入表:

COPY test from local 'abc.data' REJECTED DATA as TABLE test_rejected;

Then, you can analyze test_rejected with sql然后,你可以用sql分析test_rejected

dbadmin=> \x
Expanded display is on.
dbadmin=> select * from test_rejected limit 1;
-[ RECORD 1 ]---+------------------------------------------------------------------
file_name       | abc.data
row_number      | 1
rejected_data   | 1237232632624232123243214
rejected_reason | int8 out of range '1237232632624232123243214' for column 1 (col1)

If you wish to fail COPY command on every bad row use ABORT ON ERROR .如果您希望在每个坏行上都失败COPY命令,请使用ABORT ON ERROR eg:例如:

dbadmin=> COPY test from local 'abc.data' ABORT ON ERROR;
ERROR 2035:  COPY: Input record 1 has been rejected (int8 out of range '1237232632624232123243214' for column 1 (col1))

You can use REJECTMAX 1 if you want the copy command to fail with an error message when a row is rejected (although it won't be specific).如果您希望复制命令在行被拒绝时失败并显示错误消息,则可以使用REJECTMAX 1 (尽管它不是特定的)。 Then you can investigate further using the exceptions and rejected data files or rejected data table.然后您可以使用异常和被拒绝的数据文件或被拒绝的数据表进一步调查。

Further reading in the documentation on load errors: https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AdministratorsGuide/BulkLoadCOPY/CapturingLoadExceptionsAndRejections.htm进一步阅读有关加载错误的文档: https : //www.vertica.com/docs/9.2.x/HTML/Content/Authoring/AdministratorsGuide/BulkLoadCOPY/CapturingLoadExceptionsAndRejections.htm

尝试这个:

load data infile 'abc.data' into table test fields terminated by ',';

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

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