78#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
79#define OCTVALUE(c) ((c) - '0')
97#define IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(extralen) \
100 if (input_buf_ptr + (extralen) >= copy_buf_len && !hit_eof) \
102 input_buf_ptr = prev_raw_ptr; \
109#define IF_NEED_REFILL_AND_EOF_BREAK(extralen) \
112 if (input_buf_ptr + (extralen) >= copy_buf_len && hit_eof) \
115 input_buf_ptr = copy_buf_len; \
126#define REFILL_LINEBUF \
129 if (input_buf_ptr > cstate->input_buf_index) \
131 appendBinaryStringInfo(&cstate->line_buf, \
132 cstate->input_buf + cstate->input_buf_index, \
133 input_buf_ptr - cstate->input_buf_index); \
134 cstate->input_buf_index = input_buf_ptr; \
180 for (
i = 0;
i < natts;
i++)
200 errmsg(
"COPY file signature not recognized")));
205 errmsg(
"invalid COPY file header (missing flags)")));
206 if ((tmp & (1 << 16)) != 0)
209 errmsg(
"invalid COPY file header (WITH OIDS)")));
211 if ((tmp >> 16) != 0)
214 errmsg(
"unrecognized critical flags in COPY file header")));
220 errmsg(
"invalid COPY file header (missing length)")));
227 errmsg(
"invalid COPY file header (wrong length)")));
256 errmsg(
"could not read from COPY file: %m")));
278 errmsg(
"unexpected EOF on client connection with an open transaction")));
294 errmsg(
"unexpected message type 0x%02X during COPY from stdin",
303 errmsg(
"unexpected EOF on client connection with an open transaction")));
317 errmsg(
"COPY from stdin failed: %s",
579 elog(
ERROR,
"encoding conversion failed without error");
630 cstate->
raw_buf[nbytes] =
'\0';
811 errmsg(
"wrong number of fields in header line: got %d, expected %d",
827 errmsg(
"column name mismatch in header line field %d: got null value (\"%s\"), expected \"%s\"",
834 errmsg(
"column name mismatch in header line field %d: got \"%s\", expected \"%s\"",
887 int *defmap = cstate->
defmap;
907 for (
i = 0;
i < num_defaults;
i++)
971 errmsg(
"extra data after last expected column")));
985 errmsg(
"missing data for column \"%s\"",
998 if (
string ==
NULL &&
1065 errmsg(
"skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": \"%s\"",
1073 errmsg(
"skipping row due to data type incompatibility at line %" PRIu64 " for column \"%s\": null input",
1131 errmsg(
"received copy data after EOF marker")));
1138 errmsg(
"row field count is %d, expected %d",
1250 bool result =
false;
1403 errmsg(
"literal carriage return found in data") :
1404 errmsg(
"unquoted carriage return found in data"),
1406 errhint(
"Use \"\\r\" to represent carriage return.") :
1407 errhint(
"Use quoted CSV field to represent carriage return.")));
1420 errmsg(
"literal carriage return found in data") :
1421 errmsg(
"unquoted carriage return found in data"),
1423 errhint(
"Use \"\\r\" to represent carriage return.") :
1424 errhint(
"Use quoted CSV field to represent carriage return.")));
1436 errmsg(
"literal newline found in data") :
1437 errmsg(
"unquoted newline found in data"),
1439 errhint(
"Use \"\\n\" to represent newline.") :
1440 errhint(
"Use quoted CSV field to represent newline.")));
1478 errmsg(
"end-of-copy marker does not match previous newline style")));
1479 else if (
c2 !=
'\r')
1482 errmsg(
"end-of-copy marker is not alone on its line")));
1490 if (
c2 !=
'\r' &&
c2 !=
'\n')
1493 errmsg(
"end-of-copy marker is not alone on its line")));
1500 errmsg(
"end-of-copy marker does not match previous newline style")));
1509 errmsg(
"end-of-copy marker is not alone on its line")));
1590 errmsg(
"extra data after last expected column")));
1619 bool saw_non_ascii =
false;
1697 saw_non_ascii =
true;
1722 saw_non_ascii =
true;
1782 errmsg(
"unexpected default marker in COPY data"),
1783 errdetail(
"Column \"%s\" has no default value.",
1846 errmsg(
"extra data after last expected column")));
1930 errmsg(
"unterminated CSV quoted field")));
1997 errmsg(
"unexpected default marker in COPY data"),
1998 errdetail(
"Column \"%s\" has no default value.",
2032 errmsg(
"unexpected EOF in COPY data")));
2041 errmsg(
"invalid field size")));
2051 errmsg(
"unexpected EOF in COPY data")));
2058 typioparam, typmod);
2064 errmsg(
"incorrect binary data format")));
void pgstat_progress_update_param(int index, int64 val)
static Datum values[MAXATTR]
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
#define pg_attribute_always_inline
#define MemSet(start, val, len)
char * CopyLimitPrintoutLength(const char *str)
#define RAW_BUF_BYTES(cstate)
#define INPUT_BUF_BYTES(cstate)
static pg_attribute_always_inline bool CopyFromTextLikeOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls, bool is_csv)
static pg_attribute_always_inline bool NextCopyFromRawFieldsInternal(CopyFromState cstate, char ***fields, int *nfields, bool is_csv)
bool CopyFromTextOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
bool CopyFromCSVOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
static int CopyReadAttributesCSV(CopyFromState cstate)
static bool CopyGetInt16(CopyFromState cstate, int16 *val)
static void CopyConversionError(CopyFromState cstate)
static bool CopyGetInt32(CopyFromState cstate, int32 *val)
static void CopyLoadRawBuf(CopyFromState cstate)
static void CopyLoadInputBuf(CopyFromState cstate)
void ReceiveCopyBinaryHeader(CopyFromState cstate)
static int CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
static Datum CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo, Oid typioparam, int32 typmod, bool *isnull)
static int GetDecimalFromHex(char hex)
void ReceiveCopyBegin(CopyFromState cstate)
static bool CopyReadLineText(CopyFromState cstate, bool is_csv)
#define IF_NEED_REFILL_AND_EOF_BREAK(extralen)
static int CopyReadAttributesText(CopyFromState cstate)
static const char BinarySignature[11]
#define IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(extralen)
static bool CopyReadLine(CopyFromState cstate, bool is_csv)
static int CopyReadBinaryData(CopyFromState cstate, char *dest, int nbytes)
bool CopyFromBinaryOneRow(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
static void CopyConvertBuf(CopyFromState cstate)
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
bool NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, Node *escontext, Datum *result)
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
@ COPY_LOG_VERBOSITY_VERBOSE
#define COPY_HEADER_MATCH
#define COPY_HEADER_FALSE
#define PQ_SMALL_MESSAGE_LIMIT
#define PQ_LARGE_MESSAGE_LIMIT
int GetDatabaseEncoding(void)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
void report_invalid_encoding(int encoding, const char *mbstr, int len)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
#define HOLD_CANCEL_INTERRUPTS()
#define RESUME_CANCEL_INTERRUPTS()
int namestrcmp(Name name, const char *str)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
static int list_nth_int(const List *list, int n)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define MAX_CONVERSION_INPUT_LENGTH
static unsigned char pg_ascii_tolower(unsigned char ch)
int pq_getmessage(StringInfo s, int maxlen)
void pq_startmsgread(void)
#define PROGRESS_COPY_BYTES_PROCESSED
#define PqMsg_CopyInResponse
#define RelationGetDescr(relation)
StringInfo makeStringInfo(void)
void resetStringInfo(StringInfo str)
void enlargeStringInfo(StringInfo str, int needed)
bool(* CopyFromOneRow)(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
copy_data_source_cb data_source_cb
const struct CopyFromRoutine * routine
StringInfoData attribute_buf
bool * convert_select_flags
ErrorSaveContext * escontext
MemoryContext ecxt_per_tuple_memory
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
int pg_encoding_max_length(int encoding)