1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-07 11:02:12 +03:00

Re-export NextCopyFromRawFields() to copy.h.

Commit 7717f630069 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
This commit is contained in:
Masahiko Sawada 2025-02-28 15:11:41 -08:00
parent e636da9200
commit 8a1012b35d
2 changed files with 25 additions and 5 deletions

View File

@ -152,6 +152,10 @@ static pg_attribute_always_inline bool CopyFromTextLikeOneRow(CopyFromState csta
Datum *values, Datum *values,
bool *nulls, bool *nulls,
bool is_csv); bool is_csv);
static pg_attribute_always_inline bool NextCopyFromRawFieldsInternal(CopyFromState cstate,
char ***fields,
int *nfields,
bool is_csv);
/* Low-level communications functions */ /* Low-level communications functions */
@ -736,8 +740,21 @@ CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
} }
/* /*
* Read raw fields in the next line for COPY FROM in text or csv mode. * This function is exposed for use by extensions that read raw fields in the
* Return false if no more lines. * next line. See NextCopyFromRawFieldsInternal() for details.
*/
bool
NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
{
return NextCopyFromRawFieldsInternal(cstate, fields, nfields,
cstate->opts.csv_mode);
}
/*
* Workhorse for NextCopyFromRawFields().
*
* Read raw fields in the next line for COPY FROM in text or csv mode. Return
* false if no more lines.
* *
* An internal temporary buffer is returned via 'fields'. It is valid until * An internal temporary buffer is returned via 'fields'. It is valid until
* the next call of the function. Since the function returns all raw fields * the next call of the function. Since the function returns all raw fields
@ -747,10 +764,11 @@ CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
* NOTE: force_not_null option are not applied to the returned fields. * NOTE: force_not_null option are not applied to the returned fields.
* *
* We use pg_attribute_always_inline to reduce function call overhead * We use pg_attribute_always_inline to reduce function call overhead
* and to help compilers to optimize away the 'is_csv' condition. * and to help compilers to optimize away the 'is_csv' condition when called
* by internal functions such as CopyFromTextLikeOneRow().
*/ */
static pg_attribute_always_inline bool static pg_attribute_always_inline bool
NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields, bool is_csv) NextCopyFromRawFieldsInternal(CopyFromState cstate, char ***fields, int *nfields, bool is_csv)
{ {
int fldct; int fldct;
bool done; bool done;
@ -934,7 +952,7 @@ CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext,
attr_count = list_length(cstate->attnumlist); attr_count = list_length(cstate->attnumlist);
/* read raw fields in the next line */ /* read raw fields in the next line */
if (!NextCopyFromRawFields(cstate, &field_strings, &fldct, is_csv)) if (!NextCopyFromRawFieldsInternal(cstate, &field_strings, &fldct, is_csv))
return false; return false;
/* check for overflowing fields */ /* check for overflowing fields */

View File

@ -107,6 +107,8 @@ extern CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *where
extern void EndCopyFrom(CopyFromState cstate); extern void EndCopyFrom(CopyFromState cstate);
extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
Datum *values, bool *nulls); Datum *values, bool *nulls);
extern bool NextCopyFromRawFields(CopyFromState cstate,
char ***fields, int *nfields);
extern void CopyFromErrorCallback(void *arg); extern void CopyFromErrorCallback(void *arg);
extern char *CopyLimitPrintoutLength(const char *str); extern char *CopyLimitPrintoutLength(const char *str);