Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite7834a1

Browse files
committed
Add log_verbosity = 'silent' support to COPY command.
Previously, when the on_error option was set to ignore, the COPY commandwould always log NOTICE messages for input rows discarded due todata type incompatibility. Users had no way to suppress these messages.This commit introduces a new log_verbosity setting, 'silent',which prevents the COPY command from emitting NOTICE messageswhen on_error = 'ignore' is used, even if rows are discarded.This feature is particularly useful when processing malformed filesfrequently, where a flood of NOTICE messages can be undesirable.For example, when frequently loading malformed files via the COPY commandor querying foreign tables using file_fdw (with an upcoming patch toadd on_error support for file_fdw), users may prefer to suppressthese messages to reduce log noise and improve clarity.Author: Atsushi TorikoshiReviewed-by: Masahiko Sawada, Fujii MasaoDiscussion:https://postgr.es/m/ab59dad10490ea3734cf022b16c24cfd@oss.nttdata.com
1 parentbabb399 commite7834a1

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

‎doc/src/sgml/ref/copy.sgml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
407407
<literal>verbose</literal>, a <literal>NOTICE</literal> message
408408
containing the line of the input file and the column name whose input
409409
conversion has failed is emitted for each discarded row.
410+
When it is set to <literal>silent</literal>, no message is emitted
411+
regarding ignored rows.
410412
</para>
411413
</listitem>
412414
</varlistentry>
@@ -428,9 +430,11 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
428430
<listitem>
429431
<para>
430432
Specifies the amount of messages emitted by a <command>COPY</command>
431-
command: <literal>default</literal> or <literal>verbose</literal>. If
432-
<literal>verbose</literal> is specified, additional messages are emitted
433-
during processing.
433+
command: <literal>default</literal>, <literal>verbose</literal>, or
434+
<literal>silent</literal>.
435+
If <literal>verbose</literal> is specified, additional messages are
436+
emitted during processing.
437+
<literal>silent</literal> suppresses both verbose and default messages.
434438
</para>
435439
<para>
436440
This is currently used in <command>COPY FROM</command> command when

‎src/backend/commands/copy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,11 @@ defGetCopyLogVerbosityChoice(DefElem *def, ParseState *pstate)
427427
char*sval;
428428

429429
/*
430-
* Allow "default", or "verbose" values.
430+
* Allow "silent", "default", or "verbose" values.
431431
*/
432432
sval=defGetString(def);
433+
if (pg_strcasecmp(sval,"silent")==0)
434+
returnCOPY_LOG_VERBOSITY_SILENT;
433435
if (pg_strcasecmp(sval,"default")==0)
434436
returnCOPY_LOG_VERBOSITY_DEFAULT;
435437
if (pg_strcasecmp(sval,"verbose")==0)

‎src/backend/commands/copyfrom.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ CopyFrom(CopyFromState cstate)
13201320
error_context_stack=errcallback.previous;
13211321

13221322
if (cstate->opts.on_error!=COPY_ON_ERROR_STOP&&
1323-
cstate->num_errors>0)
1323+
cstate->num_errors>0&&
1324+
cstate->opts.log_verbosity >=COPY_LOG_VERBOSITY_DEFAULT)
13241325
ereport(NOTICE,
13251326
errmsg_plural("%llu row was skipped due to data type incompatibility",
13261327
"%llu rows were skipped due to data type incompatibility",

‎src/bin/psql/tab-complete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,7 @@ psql_completion(const char *text, int start, int end)
29162916

29172917
/* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */
29182918
elseif (Matches("COPY|\\copy",MatchAny,"FROM|TO",MatchAny,"WITH","(","LOG_VERBOSITY"))
2919-
COMPLETE_WITH("default","verbose");
2919+
COMPLETE_WITH("silent","default","verbose");
29202920

29212921
/* Complete COPY <sth> FROM <sth> WITH (<options>) */
29222922
elseif (Matches("COPY|\\copy",MatchAny,"FROM",MatchAny,"WITH",MatchAny))

‎src/include/commands/copy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ typedef enum CopyOnErrorChoice
4545
*/
4646
typedefenumCopyLogVerbosityChoice
4747
{
48-
COPY_LOG_VERBOSITY_DEFAULT=0,/* logs no additional messages, default */
48+
COPY_LOG_VERBOSITY_SILENT=-1,/* logs none */
49+
COPY_LOG_VERBOSITY_DEFAULT=0,/* logs no additional messages. As this is
50+
* the default, assign 0 */
4951
COPY_LOG_VERBOSITY_VERBOSE,/* logs additional messages */
5052
}CopyLogVerbosityChoice;
5153

‎src/test/regress/expected/copy2.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ COPY check_ign_err2 FROM STDIN WITH (on_error ignore, log_verbosity verbose);
760760
NOTICE: skipping row due to data type incompatibility at line 2 for column "l": null input
761761
CONTEXT: COPY check_ign_err2
762762
NOTICE: 1 row was skipped due to data type incompatibility
763+
COPY check_ign_err2 FROM STDIN WITH (on_error ignore, log_verbosity silent);
763764
-- reset context choice
764765
\set SHOW_CONTEXT errors
765766
SELECT * FROM check_ign_err;
@@ -774,7 +775,8 @@ SELECT * FROM check_ign_err2;
774775
n | m | k | l
775776
---+-----+---+-------
776777
1 | {1} | 1 | 'foo'
777-
(1 row)
778+
3 | {3} | 3 | 'bar'
779+
(2 rows)
778780

779781
-- test datatype error that can't be handled as soft: should fail
780782
CREATE TABLE hard_err(foo widget);

‎src/test/regress/sql/copy2.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ COPY check_ign_err2 FROM STDIN WITH (on_error ignore, log_verbosity verbose);
533533
1{1}1'foo'
534534
2{2}2\N
535535
\.
536+
COPY check_ign_err2FROM STDIN WITH (on_error ignore, log_verbosity silent);
537+
3{3}3'bar'
538+
4{4}4\N
539+
\.
536540

537541
-- reset context choice
538542
\set SHOW_CONTEXT errors

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp