diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-02-05 09:46:02 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-02-05 09:46:02 +0900 |
commit | 95fb5b49024aa51310f91aba669aaf0bb3227932 (patch) | |
tree | 7ccf2f1642c692fdbd45b864052fa257d9a40ee8 /src/backend/commands/copyfrom.c | |
parent | 774bcffe4a9853a24e61d758637c0aad2871f1fb (diff) | |
download | postgresql-95fb5b49024aa51310f91aba669aaf0bb3227932.tar.gz postgresql-95fb5b49024aa51310f91aba669aaf0bb3227932.zip |
Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM
CopyReadAttributes{CSV,Text}() are used to parse lines for text and CSV
format. This reduces the number of "if" branches that need to be
checked when parsing fields in CSV and text mode when dealing with a
COPY FROM, something that can become more noticeable with more
attributes and more lines to process.
Extracted from a larger patch by the same author.
Author: Sutou Kouhei
Discussion: https://postgr.es/m/20231204.153548.2126325458835528809.kou@clear-code.com
Diffstat (limited to 'src/backend/commands/copyfrom.c')
-rw-r--r-- | src/backend/commands/copyfrom.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 1fe70b91338..41f6bc43e49 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -1776,6 +1776,11 @@ BeginCopyFrom(ParseState *pstate, cstate->max_fields = attr_count; cstate->raw_fields = (char **) palloc(attr_count * sizeof(char *)); + + if (cstate->opts.csv_mode) + cstate->copy_read_attributes = CopyReadAttributesCSV; + else + cstate->copy_read_attributes = CopyReadAttributesText; } MemoryContextSwitchTo(oldcontext); |