Skip to content

Commit 8a1012b

Browse files
Re-export NextCopyFromRawFields() to copy.h.
Commit 7717f63 removed NextCopyFromRawFields() from copy.h. While it was hoped that NextCopyFrom() could serve as an alternative, certain use cases still require NextCopyFromRawFields(). For instance, extensions like file_text_array_fdw, which process source data with an unknown number of columns, rely on this function. Per buildfarm member crake. Reported-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Sutou Kouhei <kou@clear-code.com> Discussion: https://postgr.es/m/5c7e1ac8-5083-4c08-af19-cb9ade2f16ce@dunslane.net
1 parent e636da9 commit 8a1012b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/backend/commands/copyfromparse.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ static pg_attribute_always_inline bool CopyFromTextLikeOneRow(CopyFromState csta
152152
Datum *values,
153153
bool *nulls,
154154
bool is_csv);
155+
static pg_attribute_always_inline bool NextCopyFromRawFieldsInternal(CopyFromState cstate,
156+
char ***fields,
157+
int *nfields,
158+
bool is_csv);
155159

156160

157161
/* Low-level communications functions */
@@ -736,8 +740,21 @@ CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
736740
}
737741

738742
/*
739-
* Read raw fields in the next line for COPY FROM in text or csv mode.
740-
* Return false if no more lines.
743+
* This function is exposed for use by extensions that read raw fields in the
744+
* next line. See NextCopyFromRawFieldsInternal() for details.
745+
*/
746+
bool
747+
NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
748+
{
749+
return NextCopyFromRawFieldsInternal(cstate, fields, nfields,
750+
cstate->opts.csv_mode);
751+
}
752+
753+
/*
754+
* Workhorse for NextCopyFromRawFields().
755+
*
756+
* Read raw fields in the next line for COPY FROM in text or csv mode. Return
757+
* false if no more lines.
741758
*
742759
* An internal temporary buffer is returned via 'fields'. It is valid until
743760
* the next call of the function. Since the function returns all raw fields
@@ -747,10 +764,11 @@ CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
747764
* NOTE: force_not_null option are not applied to the returned fields.
748765
*
749766
* We use pg_attribute_always_inline to reduce function call overhead
750-
* and to help compilers to optimize away the 'is_csv' condition.
767+
* and to help compilers to optimize away the 'is_csv' condition when called
768+
* by internal functions such as CopyFromTextLikeOneRow().
751769
*/
752770
static pg_attribute_always_inline bool
753-
NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields, bool is_csv)
771+
NextCopyFromRawFieldsInternal(CopyFromState cstate, char ***fields, int *nfields, bool is_csv)
754772
{
755773
int fldct;
756774
bool done;
@@ -934,7 +952,7 @@ CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext,
934952
attr_count = list_length(cstate->attnumlist);
935953

936954
/* read raw fields in the next line */
937-
if (!NextCopyFromRawFields(cstate, &field_strings, &fldct, is_csv))
955+
if (!NextCopyFromRawFieldsInternal(cstate, &field_strings, &fldct, is_csv))
938956
return false;
939957

940958
/* check for overflowing fields */

src/include/commands/copy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ extern CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *where
107107
extern void EndCopyFrom(CopyFromState cstate);
108108
extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
109109
Datum *values, bool *nulls);
110+
extern bool NextCopyFromRawFields(CopyFromState cstate,
111+
char ***fields, int *nfields);
110112
extern void CopyFromErrorCallback(void *arg);
111113
extern char *CopyLimitPrintoutLength(const char *str);
112114

0 commit comments

Comments
 (0)