1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-21 05:21:08 +03:00

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
This commit is contained in:
Michael Paquier
2024-02-05 09:46:02 +09:00
parent 774bcffe4a
commit 95fb5b4902
3 changed files with 30 additions and 16 deletions

View File

@@ -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);