mirror of
https://github.com/postgres/postgres.git
synced 2025-10-28 11:55:03 +03:00
Add new COPY option LOG_VERBOSITY.
This commit adds a new COPY option LOG_VERBOSITY, which controls the amount of messages emitted during processing. Valid values are 'default' and 'verbose'. This is currently used in COPY FROM when ON_ERROR option is set to ignore. If 'verbose' is specified, a NOTICE message is emitted for each discarded row, providing additional information such as line number, column name, and the malformed value. This helps users to identify problematic rows that failed to load. Author: Bharath Rupireddy Reviewed-by: Michael Paquier, Atsushi Torikoshi, Masahiko Sawada Discussion: https://www.postgresql.org/message-id/CALj2ACUk700cYhx1ATRQyRw-fBM%2BaRo6auRAitKGff7XNmYfqQ%40mail.gmail.com
This commit is contained in:
@@ -422,6 +422,30 @@ defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from)
|
||||
return COPY_ON_ERROR_STOP; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract a CopyLogVerbosityChoice value from a DefElem.
|
||||
*/
|
||||
static CopyLogVerbosityChoice
|
||||
defGetCopyLogVerbosityChoice(DefElem *def, ParseState *pstate)
|
||||
{
|
||||
char *sval;
|
||||
|
||||
/*
|
||||
* Allow "default", or "verbose" values.
|
||||
*/
|
||||
sval = defGetString(def);
|
||||
if (pg_strcasecmp(sval, "default") == 0)
|
||||
return COPY_LOG_VERBOSITY_DEFAULT;
|
||||
if (pg_strcasecmp(sval, "verbose") == 0)
|
||||
return COPY_LOG_VERBOSITY_VERBOSE;
|
||||
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("COPY LOG_VERBOSITY \"%s\" not recognized", sval),
|
||||
parser_errposition(pstate, def->location)));
|
||||
return COPY_LOG_VERBOSITY_DEFAULT; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* Process the statement option list for COPY.
|
||||
*
|
||||
@@ -448,6 +472,7 @@ ProcessCopyOptions(ParseState *pstate,
|
||||
bool freeze_specified = false;
|
||||
bool header_specified = false;
|
||||
bool on_error_specified = false;
|
||||
bool log_verbosity_specified = false;
|
||||
ListCell *option;
|
||||
|
||||
/* Support external use for option sanity checking */
|
||||
@@ -607,6 +632,13 @@ ProcessCopyOptions(ParseState *pstate,
|
||||
on_error_specified = true;
|
||||
opts_out->on_error = defGetCopyOnErrorChoice(defel, pstate, is_from);
|
||||
}
|
||||
else if (strcmp(defel->defname, "log_verbosity") == 0)
|
||||
{
|
||||
if (log_verbosity_specified)
|
||||
errorConflictingDefElem(defel, pstate);
|
||||
log_verbosity_specified = true;
|
||||
opts_out->log_verbosity = defGetCopyLogVerbosityChoice(defel, pstate);
|
||||
}
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
|
||||
Reference in New Issue
Block a user