64 int stmt_location,
int stmt_len,
67 bool is_from =
stmt->is_from;
68 bool pipe = (
stmt->filename ==
NULL);
85 errmsg(
"permission denied to COPY to or from an external program"),
86 errdetail(
"Only roles with privileges of the \"%s\" role may COPY to or from an external program.",
87 "pg_execute_server_program"),
88 errhint(
"Anyone can COPY to stdout or from stdin. "
89 "psql's \\copy command also works for anyone.")));
96 errmsg(
"permission denied to COPY from a file"),
97 errdetail(
"Only roles with privileges of the \"%s\" role may COPY from a file.",
98 "pg_read_server_files"),
99 errhint(
"Anyone can COPY to stdout or from stdin. "
100 "psql's \\copy command also works for anyone.")));
105 errmsg(
"permission denied to COPY to a file"),
106 errdetail(
"Only roles with privileges of the \"%s\" role may COPY to a file.",
107 "pg_write_server_files"),
108 errhint(
"Anyone can COPY to stdout or from stdin. "
109 "psql's \\copy command also works for anyone.")));
135 if (
stmt->whereClause)
183 errmsg(
"generated columns are not supported in COPY FROM WHERE conditions"),
184 errdetail(
"Column \"%s\" is a generated column.",
196 foreach(
cur, attnums)
233 errmsg(
"COPY FROM not supported with row-level security"),
234 errhint(
"Use INSERT statements instead.")));
266 foreach(
lc,
stmt->attlist)
285 targetList =
lappend(targetList, target);
306 select->targetList = targetList;
417 errmsg(
"cannot use \"%s\" with HEADER in COPY TO",
432 errmsg(
"%s requires a Boolean value, an integer "
433 "value greater than or equal to zero, "
434 "or the string \"%s\"",
444 errmsg(
"a negative integer value cannot be "
445 "specified for %s", def->
defname)));
447 if (!is_from && ival > 1)
450 errmsg(
"cannot use multi-line header in COPY TO")));
468 errmsg(
"COPY %s cannot be used with %s",
"ON_ERROR",
"COPY TO"),
482 errmsg(
"COPY %s \"%s\" not recognized",
"ON_ERROR", sval),
502 errmsg(
"%s requires a numeric value",
509 if (reject_limit <= 0)
512 errmsg(
"REJECT_LIMIT (%" PRId64 ") must be greater than zero",
540 errmsg(
"COPY %s \"%s\" not recognized",
"LOG_VERBOSITY", sval),
602 errmsg(
"COPY format \"%s\" not recognized",
fmt),
649 else if (
strcmp(
defel->defname,
"force_quote") == 0)
660 errmsg(
"argument to option \"%s\" must be a list of column names",
664 else if (
strcmp(
defel->defname,
"force_not_null") == 0)
675 errmsg(
"argument to option \"%s\" must be a list of column names",
679 else if (
strcmp(
defel->defname,
"force_null") == 0)
690 errmsg(
"argument to option \"%s\" must be a list of column names",
694 else if (
strcmp(
defel->defname,
"convert_selectively") == 0)
703 opts_out->convert_selectively =
true;
709 errmsg(
"argument to option \"%s\" must be a list of column names",
721 errmsg(
"argument to option \"%s\" must be a valid encoding name",
732 else if (
strcmp(
defel->defname,
"log_verbosity") == 0)
739 else if (
strcmp(
defel->defname,
"reject_limit") == 0)
749 errmsg(
"option \"%s\" not recognized",
762 errmsg(
"cannot specify %s in BINARY mode",
"DELIMITER")));
767 errmsg(
"cannot specify %s in BINARY mode",
"NULL")));
772 errmsg(
"cannot specify %s in BINARY mode",
"DEFAULT")));
794 errmsg(
"COPY delimiter must be a single one-byte character")));
801 errmsg(
"COPY delimiter cannot be newline or carriage return")));
807 errmsg(
"COPY null representation cannot use newline or carriage return")));
817 errmsg(
"COPY default representation cannot use newline or carriage return")));
831 strchr(
"\\.abcdefghijklmnopqrstuvwxyz0123456789",
842 errmsg(
"cannot specify %s in BINARY mode",
"HEADER")));
849 errmsg(
"COPY %s requires CSV mode",
"QUOTE")));
854 errmsg(
"COPY quote must be a single one-byte character")));
859 errmsg(
"COPY delimiter and quote must be different")));
866 errmsg(
"COPY %s requires CSV mode",
"ESCAPE")));
871 errmsg(
"COPY escape must be a single one-byte character")));
878 errmsg(
"COPY %s requires CSV mode",
"FORCE_QUOTE")));
884 errmsg(
"COPY %s cannot be used with %s",
"FORCE_QUOTE",
893 errmsg(
"COPY %s requires CSV mode",
"FORCE_NOT_NULL")));
900 errmsg(
"COPY %s cannot be used with %s",
"FORCE_NOT_NULL",
909 errmsg(
"COPY %s requires CSV mode",
"FORCE_NULL")));
917 errmsg(
"COPY %s cannot be used with %s",
"FORCE_NULL",
925 errmsg(
"COPY delimiter character must not appear in the %s specification",
934 errmsg(
"CSV quote character must not appear in the %s specification",
943 errmsg(
"COPY %s cannot be used with %s",
"FREEZE",
953 errmsg(
"COPY %s cannot be used with %s",
"DEFAULT",
961 errmsg(
"COPY delimiter character must not appear in the %s specification",
970 errmsg(
"CSV quote character must not appear in the %s specification",
979 errmsg(
"NULL specification and DEFAULT specification cannot be the same")));
985 errmsg(
"only ON_ERROR STOP is allowed in BINARY mode")));
992 errmsg(
"COPY %s requires %s to be set to %s",
993 "REJECT_LIMIT",
"ON_ERROR",
"IGNORE")));
1043 for (
i = 0;
i < tupDesc->
natts;
i++)
1047 if (
att->attisdropped)
1051 if (
att->attgenerated)
1054 errmsg(
"column \"%s\" is a generated column",
1056 errdetail(
"Generated columns cannot be used in COPY.")));
1066 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
1071 errmsg(
"column \"%s\" does not exist",
1078 errmsg(
"column \"%s\" specified more than once",
bool has_privs_of_role(Oid member, Oid role)
#define InvalidAttrNumber
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
static int defGetCopyHeaderOption(DefElem *def, bool is_from)
static int64 defGetCopyRejectLimitOption(DefElem *def)
List * CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
static CopyOnErrorChoice defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from)
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
static CopyLogVerbosityChoice defGetCopyLogVerbosityChoice(DefElem *def, ParseState *pstate)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define Assert(condition)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *whereClause, const char *filename, bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options)
uint64 CopyFrom(CopyFromState cstate)
void EndCopyFrom(CopyFromState cstate)
uint64 DoCopyTo(CopyToState cstate)
CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *raw_query, Oid queryRelId, const char *filename, bool is_program, copy_data_dest_cb data_dest_cb, List *attnamelist, List *options)
void EndCopyTo(CopyToState cstate)
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
int64 defGetInt64(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool ExecCheckPermissions(List *rangeTable, List *rteperminfos, bool ereport_on_violation)
#define palloc0_object(type)
@ COPY_LOG_VERBOSITY_SILENT
@ COPY_LOG_VERBOSITY_VERBOSE
@ COPY_LOG_VERBOSITY_DEFAULT
#define COPY_HEADER_MATCH
#define COPY_HEADER_FALSE
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
bool list_member_int(const List *list, int datum)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
char * get_namespace_name(Oid nspid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
List * make_ands_implicit(Expr *clause)
char * pstrdup(const char *in)
int namestrcmp(Name name, const char *str)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
int64 pg_strtoint64(const char *s)
int32 pg_strtoint32_safe(const char *s, Node *escontext)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
FormData_pg_attribute * Form_pg_attribute
#define lfirst_node(type, lc)
#define pg_char_to_encoding
int pg_strcasecmp(const char *s1, const char *s2)
Expr * canonicalize_qual(Expr *qual, bool is_check)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
int check_enable_rls(Oid relid, Oid checkAsUser, bool noError)
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
void PreventCommandIfReadOnly(const char *cmdname)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
#define select(n, r, w, e, timeout)