mirror of
https://github.com/postgres/postgres.git
synced 2026-01-29 12:02:15 +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:
@@ -52,6 +52,13 @@ typedef enum CopyInsertMethod
|
||||
* ExecForeignBatchInsert only if valid */
|
||||
} CopyInsertMethod;
|
||||
|
||||
/*
|
||||
* Per-format callback to parse a line into separate fields.
|
||||
*
|
||||
* Returns the number of fields read.
|
||||
*/
|
||||
typedef int (*CopyReadAttributes) (CopyFromState cstate);
|
||||
|
||||
/*
|
||||
* This struct contains all the state variables used throughout a COPY FROM
|
||||
* operation.
|
||||
@@ -130,6 +137,12 @@ typedef struct CopyFromStateData
|
||||
int max_fields;
|
||||
char **raw_fields;
|
||||
|
||||
/*
|
||||
* Per-format callback to parse lines, then fill raw_fields and
|
||||
* attribute_buf.
|
||||
*/
|
||||
CopyReadAttributes copy_read_attributes;
|
||||
|
||||
/*
|
||||
* Similarly, line_buf holds the whole input line being processed. The
|
||||
* input cycle is first to read the whole line into line_buf, and then
|
||||
@@ -183,4 +196,8 @@ typedef struct CopyFromStateData
|
||||
extern void ReceiveCopyBegin(CopyFromState cstate);
|
||||
extern void ReceiveCopyBinaryHeader(CopyFromState cstate);
|
||||
|
||||
/* Callbacks for copy_read_attributes */
|
||||
extern int CopyReadAttributesCSV(CopyFromState cstate);
|
||||
extern int CopyReadAttributesText(CopyFromState cstate);
|
||||
|
||||
#endif /* COPYFROM_INTERNAL_H */
|
||||
|
||||
Reference in New Issue
Block a user