diff options
author | Fujii Masao <fujii@postgresql.org> | 2024-11-20 23:53:19 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2024-11-20 23:53:19 +0900 |
commit | 6c8f670323d22acb62104f7f8f1b1a078dadd255 (patch) | |
tree | ce0ab487df79a15784a9e07a85e621a78725f1bc /src/backend/commands/copy.c | |
parent | 15afb7d61c142a9254a6612c6774aff4f358fb69 (diff) | |
download | postgresql-6c8f670323d22acb62104f7f8f1b1a078dadd255.tar.gz postgresql-6c8f670323d22acb62104f7f8f1b1a078dadd255.zip |
file_fdw: Add REJECT_LIMIT option to file_fdw.
Commit 4ac2a9bece introduced the REJECT_LIMIT option for the COPY
command. This commit extends the support for this option to file_fdw.
As well as REJECT_LIMIT option for COPY, this option limits
the maximum number of erroneous rows that can be skipped.
If the number of data type conversion errors exceeds this limit,
accessing the file_fdw foreign table will fail with an error,
even when on_error = 'ignore' is specified.
Since the CREATE/ALTER FOREIGN TABLE commands require foreign
table options to be single-quoted, this commit updates
defGetCopyRejectLimitOption() to handle also string value for them,
in addition to int64 value for COPY command option.
Author: Atsushi Torikoshi
Reviewed-by: Fujii Masao, Yugo Nagata, Kirill Reshke
Discussion: https://postgr.es/m/bab68a9fc502b12693f0755b6f35f327@oss.nttdata.com
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 3485ba8663f..2d98ecf3f4e 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -420,11 +420,25 @@ defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from) /* * Extract REJECT_LIMIT value from a DefElem. + * + * REJECT_LIMIT can be specified in two ways: as an int64 for the COPY command + * option or as a single-quoted string for the foreign table option using + * file_fdw. Therefore this function needs to handle both formats. */ static int64 defGetCopyRejectLimitOption(DefElem *def) { - int64 reject_limit = defGetInt64(def); + int64 reject_limit; + + if (def->arg == NULL) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("%s requires a numeric value", + def->defname))); + else if (nodeTag(def->arg) == T_String) + reject_limit = pg_strtoint64(strVal(def->arg)); + else + reject_limit = defGetInt64(def); if (reject_limit <= 0) ereport(ERROR, |