PostgreSQL Source Code  git master
copy.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/sysattr.h"
#include "access/table.h"
#include "access/xact.h"
#include "catalog/pg_authid.h"
#include "commands/copy.h"
#include "commands/defrem.h"
#include "executor/executor.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "optimizer/optimizer.h"
#include "parser/parse_coerce.h"
#include "parser/parse_collate.h"
#include "parser/parse_expr.h"
#include "parser/parse_relation.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/rls.h"
Include dependency graph for copy.c:

Go to the source code of this file.

Functions

void DoCopy (ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
 
static CopyHeaderChoice defGetCopyHeaderChoice (DefElem *def, bool is_from)
 
static CopyOnErrorChoice defGetCopyOnErrorChoice (DefElem *def, ParseState *pstate, bool is_from)
 
static int64 defGetCopyRejectLimitOption (DefElem *def)
 
static CopyLogVerbosityChoice defGetCopyLogVerbosityChoice (DefElem *def, ParseState *pstate)
 
void ProcessCopyOptions (ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
 
ListCopyGetAttnums (TupleDesc tupDesc, Relation rel, List *attnamelist)
 

Function Documentation

◆ CopyGetAttnums()

List* CopyGetAttnums ( TupleDesc  tupDesc,
Relation  rel,
List attnamelist 
)

Definition at line 931 of file copy.c.

932 {
933  List *attnums = NIL;
934 
935  if (attnamelist == NIL)
936  {
937  /* Generate default column list */
938  int attr_count = tupDesc->natts;
939  int i;
940 
941  for (i = 0; i < attr_count; i++)
942  {
943  if (TupleDescAttr(tupDesc, i)->attisdropped)
944  continue;
945  if (TupleDescAttr(tupDesc, i)->attgenerated)
946  continue;
947  attnums = lappend_int(attnums, i + 1);
948  }
949  }
950  else
951  {
952  /* Validate the user-supplied list and extract attnums */
953  ListCell *l;
954 
955  foreach(l, attnamelist)
956  {
957  char *name = strVal(lfirst(l));
958  int attnum;
959  int i;
960 
961  /* Lookup column name */
963  for (i = 0; i < tupDesc->natts; i++)
964  {
965  Form_pg_attribute att = TupleDescAttr(tupDesc, i);
966 
967  if (att->attisdropped)
968  continue;
969  if (namestrcmp(&(att->attname), name) == 0)
970  {
971  if (att->attgenerated)
972  ereport(ERROR,
973  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
974  errmsg("column \"%s\" is a generated column",
975  name),
976  errdetail("Generated columns cannot be used in COPY.")));
977  attnum = att->attnum;
978  break;
979  }
980  }
981  if (attnum == InvalidAttrNumber)
982  {
983  if (rel != NULL)
984  ereport(ERROR,
985  (errcode(ERRCODE_UNDEFINED_COLUMN),
986  errmsg("column \"%s\" of relation \"%s\" does not exist",
987  name, RelationGetRelationName(rel))));
988  else
989  ereport(ERROR,
990  (errcode(ERRCODE_UNDEFINED_COLUMN),
991  errmsg("column \"%s\" does not exist",
992  name)));
993  }
994  /* Check for duplicates */
995  if (list_member_int(attnums, attnum))
996  ereport(ERROR,
997  (errcode(ERRCODE_DUPLICATE_COLUMN),
998  errmsg("column \"%s\" specified more than once",
999  name)));
1000  attnums = lappend_int(attnums, attnum);
1001  }
1002  }
1003 
1004  return attnums;
1005 }
#define InvalidAttrNumber
Definition: attnum.h:23
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int i
Definition: isn.c:73
List * lappend_int(List *list, int datum)
Definition: list.c:357
bool list_member_int(const List *list, int datum)
Definition: list.c:702
int namestrcmp(Name name, const char *str)
Definition: name.c:247
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
#define RelationGetRelationName(relation)
Definition: rel.h:539
Definition: pg_list.h:54
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define strVal(v)
Definition: value.h:82
const char * name

References attnum, ereport, errcode(), errdetail(), errmsg(), ERROR, i, InvalidAttrNumber, lappend_int(), lfirst, list_member_int(), name, namestrcmp(), TupleDescData::natts, NIL, RelationGetRelationName, strVal, and TupleDescAttr.

Referenced by BeginCopyFrom(), BeginCopyTo(), and DoCopy().

◆ defGetCopyHeaderChoice()

static CopyHeaderChoice defGetCopyHeaderChoice ( DefElem def,
bool  is_from 
)
static

Definition at line 329 of file copy.c.

330 {
331  /*
332  * If no parameter value given, assume "true" is meant.
333  */
334  if (def->arg == NULL)
335  return COPY_HEADER_TRUE;
336 
337  /*
338  * Allow 0, 1, "true", "false", "on", "off", or "match".
339  */
340  switch (nodeTag(def->arg))
341  {
342  case T_Integer:
343  switch (intVal(def->arg))
344  {
345  case 0:
346  return COPY_HEADER_FALSE;
347  case 1:
348  return COPY_HEADER_TRUE;
349  default:
350  /* otherwise, error out below */
351  break;
352  }
353  break;
354  default:
355  {
356  char *sval = defGetString(def);
357 
358  /*
359  * The set of strings accepted here should match up with the
360  * grammar's opt_boolean_or_string production.
361  */
362  if (pg_strcasecmp(sval, "true") == 0)
363  return COPY_HEADER_TRUE;
364  if (pg_strcasecmp(sval, "false") == 0)
365  return COPY_HEADER_FALSE;
366  if (pg_strcasecmp(sval, "on") == 0)
367  return COPY_HEADER_TRUE;
368  if (pg_strcasecmp(sval, "off") == 0)
369  return COPY_HEADER_FALSE;
370  if (pg_strcasecmp(sval, "match") == 0)
371  {
372  if (!is_from)
373  ereport(ERROR,
374  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
375  errmsg("cannot use \"%s\" with HEADER in COPY TO",
376  sval)));
377  return COPY_HEADER_MATCH;
378  }
379  }
380  break;
381  }
382  ereport(ERROR,
383  (errcode(ERRCODE_SYNTAX_ERROR),
384  errmsg("%s requires a Boolean value or \"match\"",
385  def->defname)));
386  return COPY_HEADER_FALSE; /* keep compiler quiet */
387 }
char * defGetString(DefElem *def)
Definition: define.c:48
@ COPY_HEADER_TRUE
Definition: copy.h:29
@ COPY_HEADER_FALSE
Definition: copy.h:28
@ COPY_HEADER_MATCH
Definition: copy.h:30
#define nodeTag(nodeptr)
Definition: nodes.h:133
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
char * defname
Definition: parsenodes.h:817
Node * arg
Definition: parsenodes.h:818
#define intVal(v)
Definition: value.h:79

References DefElem::arg, COPY_HEADER_FALSE, COPY_HEADER_MATCH, COPY_HEADER_TRUE, defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, intVal, nodeTag, and pg_strcasecmp().

Referenced by ProcessCopyOptions().

◆ defGetCopyLogVerbosityChoice()

static CopyLogVerbosityChoice defGetCopyLogVerbosityChoice ( DefElem def,
ParseState pstate 
)
static

Definition at line 442 of file copy.c.

443 {
444  char *sval;
445 
446  /*
447  * Allow "silent", "default", or "verbose" values.
448  */
449  sval = defGetString(def);
450  if (pg_strcasecmp(sval, "silent") == 0)
452  if (pg_strcasecmp(sval, "default") == 0)
454  if (pg_strcasecmp(sval, "verbose") == 0)
456 
457  ereport(ERROR,
458  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
459  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR */
460  errmsg("COPY %s \"%s\" not recognized", "LOG_VERBOSITY", sval),
461  parser_errposition(pstate, def->location)));
462  return COPY_LOG_VERBOSITY_DEFAULT; /* keep compiler quiet */
463 }
@ COPY_LOG_VERBOSITY_SILENT
Definition: copy.h:48
@ COPY_LOG_VERBOSITY_VERBOSE
Definition: copy.h:51
@ COPY_LOG_VERBOSITY_DEFAULT
Definition: copy.h:49
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
ParseLoc location
Definition: parsenodes.h:821

References COPY_LOG_VERBOSITY_DEFAULT, COPY_LOG_VERBOSITY_SILENT, COPY_LOG_VERBOSITY_VERBOSE, defGetString(), ereport, errcode(), errmsg(), ERROR, DefElem::location, parser_errposition(), and pg_strcasecmp().

Referenced by ProcessCopyOptions().

◆ defGetCopyOnErrorChoice()

static CopyOnErrorChoice defGetCopyOnErrorChoice ( DefElem def,
ParseState pstate,
bool  is_from 
)
static

Definition at line 393 of file copy.c.

394 {
395  char *sval = defGetString(def);
396 
397  if (!is_from)
398  ereport(ERROR,
399  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
400  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
401  second %s is a COPY with direction, e.g. COPY TO */
402  errmsg("COPY %s cannot be used with %s", "ON_ERROR", "COPY TO"),
403  parser_errposition(pstate, def->location)));
404 
405  /*
406  * Allow "stop", or "ignore" values.
407  */
408  if (pg_strcasecmp(sval, "stop") == 0)
409  return COPY_ON_ERROR_STOP;
410  if (pg_strcasecmp(sval, "ignore") == 0)
411  return COPY_ON_ERROR_IGNORE;
412 
413  ereport(ERROR,
414  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
415  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR */
416  errmsg("COPY %s \"%s\" not recognized", "ON_ERROR", sval),
417  parser_errposition(pstate, def->location)));
418  return COPY_ON_ERROR_STOP; /* keep compiler quiet */
419 }
@ COPY_ON_ERROR_IGNORE
Definition: copy.h:40
@ COPY_ON_ERROR_STOP
Definition: copy.h:39

References COPY_ON_ERROR_IGNORE, COPY_ON_ERROR_STOP, defGetString(), ereport, errcode(), errmsg(), ERROR, DefElem::location, parser_errposition(), and pg_strcasecmp().

Referenced by ProcessCopyOptions().

◆ defGetCopyRejectLimitOption()

static int64 defGetCopyRejectLimitOption ( DefElem def)
static

Definition at line 425 of file copy.c.

426 {
427  int64 reject_limit = defGetInt64(def);
428 
429  if (reject_limit <= 0)
430  ereport(ERROR,
431  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
432  errmsg("REJECT_LIMIT (%lld) must be greater than zero",
433  (long long) reject_limit)));
434 
435  return reject_limit;
436 }
int64 defGetInt64(DefElem *def)
Definition: define.c:186

References defGetInt64(), ereport, errcode(), errmsg(), and ERROR.

Referenced by ProcessCopyOptions().

◆ DoCopy()

void DoCopy ( ParseState pstate,
const CopyStmt stmt,
int  stmt_location,
int  stmt_len,
uint64 *  processed 
)

Definition at line 62 of file copy.c.

65 {
66  bool is_from = stmt->is_from;
67  bool pipe = (stmt->filename == NULL);
68  Relation rel;
69  Oid relid;
70  RawStmt *query = NULL;
71  Node *whereClause = NULL;
72 
73  /*
74  * Disallow COPY to/from file or program except to users with the
75  * appropriate role.
76  */
77  if (!pipe)
78  {
79  if (stmt->is_program)
80  {
81  if (!has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM))
82  ereport(ERROR,
83  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
84  errmsg("permission denied to COPY to or from an external program"),
85  errdetail("Only roles with privileges of the \"%s\" role may COPY to or from an external program.",
86  "pg_execute_server_program"),
87  errhint("Anyone can COPY to stdout or from stdin. "
88  "psql's \\copy command also works for anyone.")));
89  }
90  else
91  {
92  if (is_from && !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES))
93  ereport(ERROR,
94  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
95  errmsg("permission denied to COPY from a file"),
96  errdetail("Only roles with privileges of the \"%s\" role may COPY from a file.",
97  "pg_read_server_files"),
98  errhint("Anyone can COPY to stdout or from stdin. "
99  "psql's \\copy command also works for anyone.")));
100 
101  if (!is_from && !has_privs_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES))
102  ereport(ERROR,
103  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
104  errmsg("permission denied to COPY to a file"),
105  errdetail("Only roles with privileges of the \"%s\" role may COPY to a file.",
106  "pg_write_server_files"),
107  errhint("Anyone can COPY to stdout or from stdin. "
108  "psql's \\copy command also works for anyone.")));
109  }
110  }
111 
112  if (stmt->relation)
113  {
114  LOCKMODE lockmode = is_from ? RowExclusiveLock : AccessShareLock;
115  ParseNamespaceItem *nsitem;
116  RTEPermissionInfo *perminfo;
117  TupleDesc tupDesc;
118  List *attnums;
119  ListCell *cur;
120 
121  Assert(!stmt->query);
122 
123  /* Open and lock the relation, using the appropriate lock type. */
124  rel = table_openrv(stmt->relation, lockmode);
125 
126  relid = RelationGetRelid(rel);
127 
128  nsitem = addRangeTableEntryForRelation(pstate, rel, lockmode,
129  NULL, false, false);
130 
131  perminfo = nsitem->p_perminfo;
132  perminfo->requiredPerms = (is_from ? ACL_INSERT : ACL_SELECT);
133 
134  if (stmt->whereClause)
135  {
136  /* add nsitem to query namespace */
137  addNSItemToQuery(pstate, nsitem, false, true, true);
138 
139  /* Transform the raw expression tree */
140  whereClause = transformExpr(pstate, stmt->whereClause, EXPR_KIND_COPY_WHERE);
141 
142  /* Make sure it yields a boolean result. */
143  whereClause = coerce_to_boolean(pstate, whereClause, "WHERE");
144 
145  /* we have to fix its collations too */
146  assign_expr_collations(pstate, whereClause);
147 
148  whereClause = eval_const_expressions(NULL, whereClause);
149 
150  whereClause = (Node *) canonicalize_qual((Expr *) whereClause, false);
151  whereClause = (Node *) make_ands_implicit((Expr *) whereClause);
152  }
153 
154  tupDesc = RelationGetDescr(rel);
155  attnums = CopyGetAttnums(tupDesc, rel, stmt->attlist);
156  foreach(cur, attnums)
157  {
158  int attno;
159  Bitmapset **bms;
160 
162  bms = is_from ? &perminfo->insertedCols : &perminfo->selectedCols;
163 
164  *bms = bms_add_member(*bms, attno);
165  }
166  ExecCheckPermissions(pstate->p_rtable, list_make1(perminfo), true);
167 
168  /*
169  * Permission check for row security policies.
170  *
171  * check_enable_rls will ereport(ERROR) if the user has requested
172  * something invalid and will otherwise indicate if we should enable
173  * RLS (returns RLS_ENABLED) or not for this COPY statement.
174  *
175  * If the relation has a row security policy and we are to apply it
176  * then perform a "query" copy and allow the normal query processing
177  * to handle the policies.
178  *
179  * If RLS is not enabled for this, then just fall through to the
180  * normal non-filtering relation handling.
181  */
182  if (check_enable_rls(relid, InvalidOid, false) == RLS_ENABLED)
183  {
185  ColumnRef *cr;
186  ResTarget *target;
187  RangeVar *from;
188  List *targetList = NIL;
189 
190  if (is_from)
191  ereport(ERROR,
192  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
193  errmsg("COPY FROM not supported with row-level security"),
194  errhint("Use INSERT statements instead.")));
195 
196  /*
197  * Build target list
198  *
199  * If no columns are specified in the attribute list of the COPY
200  * command, then the target list is 'all' columns. Therefore, '*'
201  * should be used as the target list for the resulting SELECT
202  * statement.
203  *
204  * In the case that columns are specified in the attribute list,
205  * create a ColumnRef and ResTarget for each column and add them
206  * to the target list for the resulting SELECT statement.
207  */
208  if (!stmt->attlist)
209  {
210  cr = makeNode(ColumnRef);
212  cr->location = -1;
213 
214  target = makeNode(ResTarget);
215  target->name = NULL;
216  target->indirection = NIL;
217  target->val = (Node *) cr;
218  target->location = -1;
219 
220  targetList = list_make1(target);
221  }
222  else
223  {
224  ListCell *lc;
225 
226  foreach(lc, stmt->attlist)
227  {
228  /*
229  * Build the ColumnRef for each column. The ColumnRef
230  * 'fields' property is a String node that corresponds to
231  * the column name respectively.
232  */
233  cr = makeNode(ColumnRef);
234  cr->fields = list_make1(lfirst(lc));
235  cr->location = -1;
236 
237  /* Build the ResTarget and add the ColumnRef to it. */
238  target = makeNode(ResTarget);
239  target->name = NULL;
240  target->indirection = NIL;
241  target->val = (Node *) cr;
242  target->location = -1;
243 
244  /* Add each column to the SELECT statement's target list */
245  targetList = lappend(targetList, target);
246  }
247  }
248 
249  /*
250  * Build RangeVar for from clause, fully qualified based on the
251  * relation which we have opened and locked. Use "ONLY" so that
252  * COPY retrieves rows from only the target table not any
253  * inheritance children, the same as when RLS doesn't apply.
254  */
257  -1);
258  from->inh = false; /* apply ONLY */
259 
260  /* Build query */
262  select->targetList = targetList;
263  select->fromClause = list_make1(from);
264 
265  query = makeNode(RawStmt);
266  query->stmt = (Node *) select;
267  query->stmt_location = stmt_location;
268  query->stmt_len = stmt_len;
269 
270  /*
271  * Close the relation for now, but keep the lock on it to prevent
272  * changes between now and when we start the query-based COPY.
273  *
274  * We'll reopen it later as part of the query-based COPY.
275  */
276  table_close(rel, NoLock);
277  rel = NULL;
278  }
279  }
280  else
281  {
282  Assert(stmt->query);
283 
284  query = makeNode(RawStmt);
285  query->stmt = stmt->query;
286  query->stmt_location = stmt_location;
287  query->stmt_len = stmt_len;
288 
289  relid = InvalidOid;
290  rel = NULL;
291  }
292 
293  if (is_from)
294  {
295  CopyFromState cstate;
296 
297  Assert(rel);
298 
299  /* check read-only transaction and parallel mode */
300  if (XactReadOnly && !rel->rd_islocaltemp)
301  PreventCommandIfReadOnly("COPY FROM");
302 
303  cstate = BeginCopyFrom(pstate, rel, whereClause,
304  stmt->filename, stmt->is_program,
305  NULL, stmt->attlist, stmt->options);
306  *processed = CopyFrom(cstate); /* copy from file to database */
307  EndCopyFrom(cstate);
308  }
309  else
310  {
311  CopyToState cstate;
312 
313  cstate = BeginCopyTo(pstate, rel, query, relid,
314  stmt->filename, stmt->is_program,
315  NULL, stmt->attlist, stmt->options);
316  *processed = DoCopyTo(cstate); /* copy from database to file */
317  EndCopyTo(cstate);
318  }
319 
320  if (rel != NULL)
321  table_close(rel, NoLock);
322 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:5268
List * CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
Definition: copy.c:931
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
#define Assert(condition)
Definition: c.h:849
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2254
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)
Definition: copyfrom.c:1383
uint64 CopyFrom(CopyFromState cstate)
Definition: copyfrom.c:640
void EndCopyFrom(CopyFromState cstate)
Definition: copyfrom.c:1802
uint64 DoCopyTo(CopyToState cstate)
Definition: copyto.c:747
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)
Definition: copyto.c:350
void EndCopyTo(CopyToState cstate)
Definition: copyto.c:726
struct cursor * cur
Definition: ecpg.c:28
int errhint(const char *fmt,...)
Definition: elog.c:1317
bool ExecCheckPermissions(List *rangeTable, List *rteperminfos, bool ereport_on_violation)
Definition: execMain.c:577
#define stmt
Definition: indent_codes.h:59
List * lappend(List *list, void *datum)
Definition: list.c:339
int LOCKMODE
Definition: lockdefs.h:26
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
#define RowExclusiveLock
Definition: lockdefs.h:38
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
List * make_ands_implicit(Expr *clause)
Definition: makefuncs.c:737
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:424
char * pstrdup(const char *in)
Definition: mcxt.c:1696
Oid GetUserId(void)
Definition: miscinit.c:514
#define makeNode(_type_)
Definition: nodes.h:155
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)
Definition: parse_expr.c:120
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:82
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)
#define ACL_INSERT
Definition: parsenodes.h:76
#define ACL_SELECT
Definition: parsenodes.h:77
#define lfirst_int(lc)
Definition: pg_list.h:173
#define list_make1(x1)
Definition: pg_list.h:212
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
Expr * canonicalize_qual(Expr *qual, bool is_check)
Definition: prepqual.c:293
#define RelationGetRelid(relation)
Definition: rel.h:505
#define RelationGetDescr(relation)
Definition: rel.h:531
#define RelationGetNamespace(relation)
Definition: rel.h:546
int check_enable_rls(Oid relid, Oid checkAsUser, bool noError)
Definition: rls.c:52
@ RLS_ENABLED
Definition: rls.h:45
ParseLoc location
Definition: parsenodes.h:297
List * fields
Definition: parsenodes.h:296
Definition: nodes.h:129
RTEPermissionInfo * p_perminfo
Definition: parse_node.h:292
List * p_rtable
Definition: parse_node.h:196
Bitmapset * selectedCols
Definition: parsenodes.h:1293
AclMode requiredPerms
Definition: parsenodes.h:1291
Bitmapset * insertedCols
Definition: parsenodes.h:1294
bool inh
Definition: primnodes.h:85
ParseLoc stmt_location
Definition: parsenodes.h:2023
ParseLoc stmt_len
Definition: parsenodes.h:2024
Node * stmt
Definition: parsenodes.h:2022
bool rd_islocaltemp
Definition: rel.h:61
Node * val
Definition: parsenodes.h:521
ParseLoc location
Definition: parsenodes.h:522
List * indirection
Definition: parsenodes.h:520
char * name
Definition: parsenodes.h:519
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: table.c:83
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:404
#define select(n, r, w, e, timeout)
Definition: win32_port.h:513
bool XactReadOnly
Definition: xact.c:81

References AccessShareLock, ACL_INSERT, ACL_SELECT, addNSItemToQuery(), addRangeTableEntryForRelation(), Assert, assign_expr_collations(), BeginCopyFrom(), BeginCopyTo(), bms_add_member(), canonicalize_qual(), check_enable_rls(), coerce_to_boolean(), CopyFrom(), CopyGetAttnums(), cur, DoCopyTo(), EndCopyFrom(), EndCopyTo(), ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, eval_const_expressions(), ExecCheckPermissions(), EXPR_KIND_COPY_WHERE, ColumnRef::fields, FirstLowInvalidHeapAttributeNumber, get_namespace_name(), GetUserId(), has_privs_of_role(), ResTarget::indirection, RangeVar::inh, RTEPermissionInfo::insertedCols, InvalidOid, lappend(), lfirst, lfirst_int, list_make1, ColumnRef::location, ResTarget::location, make_ands_implicit(), makeNode, makeRangeVar(), ResTarget::name, NIL, NoLock, ParseNamespaceItem::p_perminfo, ParseState::p_rtable, PreventCommandIfReadOnly(), pstrdup(), RelationData::rd_islocaltemp, RelationGetDescr, RelationGetNamespace, RelationGetRelationName, RelationGetRelid, RTEPermissionInfo::requiredPerms, RLS_ENABLED, RowExclusiveLock, select, RTEPermissionInfo::selectedCols, RawStmt::stmt, stmt, RawStmt::stmt_len, RawStmt::stmt_location, table_close(), table_openrv(), transformExpr(), ResTarget::val, and XactReadOnly.

Referenced by standard_ProcessUtility().

◆ ProcessCopyOptions()

void ProcessCopyOptions ( ParseState pstate,
CopyFormatOptions opts_out,
bool  is_from,
List options 
)

Definition at line 482 of file copy.c.

486 {
487  bool format_specified = false;
488  bool freeze_specified = false;
489  bool header_specified = false;
490  bool on_error_specified = false;
491  bool log_verbosity_specified = false;
492  bool reject_limit_specified = false;
493  ListCell *option;
494 
495  /* Support external use for option sanity checking */
496  if (opts_out == NULL)
497  opts_out = (CopyFormatOptions *) palloc0(sizeof(CopyFormatOptions));
498 
499  opts_out->file_encoding = -1;
500 
501  /* Extract options from the statement node tree */
502  foreach(option, options)
503  {
504  DefElem *defel = lfirst_node(DefElem, option);
505 
506  if (strcmp(defel->defname, "format") == 0)
507  {
508  char *fmt = defGetString(defel);
509 
510  if (format_specified)
511  errorConflictingDefElem(defel, pstate);
512  format_specified = true;
513  if (strcmp(fmt, "text") == 0)
514  /* default format */ ;
515  else if (strcmp(fmt, "csv") == 0)
516  opts_out->csv_mode = true;
517  else if (strcmp(fmt, "binary") == 0)
518  opts_out->binary = true;
519  else
520  ereport(ERROR,
521  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
522  errmsg("COPY format \"%s\" not recognized", fmt),
523  parser_errposition(pstate, defel->location)));
524  }
525  else if (strcmp(defel->defname, "freeze") == 0)
526  {
527  if (freeze_specified)
528  errorConflictingDefElem(defel, pstate);
529  freeze_specified = true;
530  opts_out->freeze = defGetBoolean(defel);
531  }
532  else if (strcmp(defel->defname, "delimiter") == 0)
533  {
534  if (opts_out->delim)
535  errorConflictingDefElem(defel, pstate);
536  opts_out->delim = defGetString(defel);
537  }
538  else if (strcmp(defel->defname, "null") == 0)
539  {
540  if (opts_out->null_print)
541  errorConflictingDefElem(defel, pstate);
542  opts_out->null_print = defGetString(defel);
543  }
544  else if (strcmp(defel->defname, "default") == 0)
545  {
546  if (opts_out->default_print)
547  errorConflictingDefElem(defel, pstate);
548  opts_out->default_print = defGetString(defel);
549  }
550  else if (strcmp(defel->defname, "header") == 0)
551  {
552  if (header_specified)
553  errorConflictingDefElem(defel, pstate);
554  header_specified = true;
555  opts_out->header_line = defGetCopyHeaderChoice(defel, is_from);
556  }
557  else if (strcmp(defel->defname, "quote") == 0)
558  {
559  if (opts_out->quote)
560  errorConflictingDefElem(defel, pstate);
561  opts_out->quote = defGetString(defel);
562  }
563  else if (strcmp(defel->defname, "escape") == 0)
564  {
565  if (opts_out->escape)
566  errorConflictingDefElem(defel, pstate);
567  opts_out->escape = defGetString(defel);
568  }
569  else if (strcmp(defel->defname, "force_quote") == 0)
570  {
571  if (opts_out->force_quote || opts_out->force_quote_all)
572  errorConflictingDefElem(defel, pstate);
573  if (defel->arg && IsA(defel->arg, A_Star))
574  opts_out->force_quote_all = true;
575  else if (defel->arg && IsA(defel->arg, List))
576  opts_out->force_quote = castNode(List, defel->arg);
577  else
578  ereport(ERROR,
579  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
580  errmsg("argument to option \"%s\" must be a list of column names",
581  defel->defname),
582  parser_errposition(pstate, defel->location)));
583  }
584  else if (strcmp(defel->defname, "force_not_null") == 0)
585  {
586  if (opts_out->force_notnull || opts_out->force_notnull_all)
587  errorConflictingDefElem(defel, pstate);
588  if (defel->arg && IsA(defel->arg, A_Star))
589  opts_out->force_notnull_all = true;
590  else if (defel->arg && IsA(defel->arg, List))
591  opts_out->force_notnull = castNode(List, defel->arg);
592  else
593  ereport(ERROR,
594  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
595  errmsg("argument to option \"%s\" must be a list of column names",
596  defel->defname),
597  parser_errposition(pstate, defel->location)));
598  }
599  else if (strcmp(defel->defname, "force_null") == 0)
600  {
601  if (opts_out->force_null || opts_out->force_null_all)
602  errorConflictingDefElem(defel, pstate);
603  if (defel->arg && IsA(defel->arg, A_Star))
604  opts_out->force_null_all = true;
605  else if (defel->arg && IsA(defel->arg, List))
606  opts_out->force_null = castNode(List, defel->arg);
607  else
608  ereport(ERROR,
609  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
610  errmsg("argument to option \"%s\" must be a list of column names",
611  defel->defname),
612  parser_errposition(pstate, defel->location)));
613  }
614  else if (strcmp(defel->defname, "convert_selectively") == 0)
615  {
616  /*
617  * Undocumented, not-accessible-from-SQL option: convert only the
618  * named columns to binary form, storing the rest as NULLs. It's
619  * allowed for the column list to be NIL.
620  */
621  if (opts_out->convert_selectively)
622  errorConflictingDefElem(defel, pstate);
623  opts_out->convert_selectively = true;
624  if (defel->arg == NULL || IsA(defel->arg, List))
625  opts_out->convert_select = castNode(List, defel->arg);
626  else
627  ereport(ERROR,
628  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
629  errmsg("argument to option \"%s\" must be a list of column names",
630  defel->defname),
631  parser_errposition(pstate, defel->location)));
632  }
633  else if (strcmp(defel->defname, "encoding") == 0)
634  {
635  if (opts_out->file_encoding >= 0)
636  errorConflictingDefElem(defel, pstate);
637  opts_out->file_encoding = pg_char_to_encoding(defGetString(defel));
638  if (opts_out->file_encoding < 0)
639  ereport(ERROR,
640  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
641  errmsg("argument to option \"%s\" must be a valid encoding name",
642  defel->defname),
643  parser_errposition(pstate, defel->location)));
644  }
645  else if (strcmp(defel->defname, "on_error") == 0)
646  {
647  if (on_error_specified)
648  errorConflictingDefElem(defel, pstate);
649  on_error_specified = true;
650  opts_out->on_error = defGetCopyOnErrorChoice(defel, pstate, is_from);
651  }
652  else if (strcmp(defel->defname, "log_verbosity") == 0)
653  {
654  if (log_verbosity_specified)
655  errorConflictingDefElem(defel, pstate);
656  log_verbosity_specified = true;
657  opts_out->log_verbosity = defGetCopyLogVerbosityChoice(defel, pstate);
658  }
659  else if (strcmp(defel->defname, "reject_limit") == 0)
660  {
661  if (reject_limit_specified)
662  errorConflictingDefElem(defel, pstate);
663  reject_limit_specified = true;
664  opts_out->reject_limit = defGetCopyRejectLimitOption(defel);
665  }
666  else
667  ereport(ERROR,
668  (errcode(ERRCODE_SYNTAX_ERROR),
669  errmsg("option \"%s\" not recognized",
670  defel->defname),
671  parser_errposition(pstate, defel->location)));
672  }
673 
674  /*
675  * Check for incompatible options (must do these three before inserting
676  * defaults)
677  */
678  if (opts_out->binary && opts_out->delim)
679  ereport(ERROR,
680  (errcode(ERRCODE_SYNTAX_ERROR),
681  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
682  errmsg("cannot specify %s in BINARY mode", "DELIMITER")));
683 
684  if (opts_out->binary && opts_out->null_print)
685  ereport(ERROR,
686  (errcode(ERRCODE_SYNTAX_ERROR),
687  errmsg("cannot specify %s in BINARY mode", "NULL")));
688 
689  if (opts_out->binary && opts_out->default_print)
690  ereport(ERROR,
691  (errcode(ERRCODE_SYNTAX_ERROR),
692  errmsg("cannot specify %s in BINARY mode", "DEFAULT")));
693 
694  /* Set defaults for omitted options */
695  if (!opts_out->delim)
696  opts_out->delim = opts_out->csv_mode ? "," : "\t";
697 
698  if (!opts_out->null_print)
699  opts_out->null_print = opts_out->csv_mode ? "" : "\\N";
700  opts_out->null_print_len = strlen(opts_out->null_print);
701 
702  if (opts_out->csv_mode)
703  {
704  if (!opts_out->quote)
705  opts_out->quote = "\"";
706  if (!opts_out->escape)
707  opts_out->escape = opts_out->quote;
708  }
709 
710  /* Only single-byte delimiter strings are supported. */
711  if (strlen(opts_out->delim) != 1)
712  ereport(ERROR,
713  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
714  errmsg("COPY delimiter must be a single one-byte character")));
715 
716  /* Disallow end-of-line characters */
717  if (strchr(opts_out->delim, '\r') != NULL ||
718  strchr(opts_out->delim, '\n') != NULL)
719  ereport(ERROR,
720  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
721  errmsg("COPY delimiter cannot be newline or carriage return")));
722 
723  if (strchr(opts_out->null_print, '\r') != NULL ||
724  strchr(opts_out->null_print, '\n') != NULL)
725  ereport(ERROR,
726  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
727  errmsg("COPY null representation cannot use newline or carriage return")));
728 
729  if (opts_out->default_print)
730  {
731  opts_out->default_print_len = strlen(opts_out->default_print);
732 
733  if (strchr(opts_out->default_print, '\r') != NULL ||
734  strchr(opts_out->default_print, '\n') != NULL)
735  ereport(ERROR,
736  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
737  errmsg("COPY default representation cannot use newline or carriage return")));
738  }
739 
740  /*
741  * Disallow unsafe delimiter characters in non-CSV mode. We can't allow
742  * backslash because it would be ambiguous. We can't allow the other
743  * cases because data characters matching the delimiter must be
744  * backslashed, and certain backslash combinations are interpreted
745  * non-literally by COPY IN. Disallowing all lower case ASCII letters is
746  * more than strictly necessary, but seems best for consistency and
747  * future-proofing. Likewise we disallow all digits though only octal
748  * digits are actually dangerous.
749  */
750  if (!opts_out->csv_mode &&
751  strchr("\\.abcdefghijklmnopqrstuvwxyz0123456789",
752  opts_out->delim[0]) != NULL)
753  ereport(ERROR,
754  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
755  errmsg("COPY delimiter cannot be \"%s\"", opts_out->delim)));
756 
757  /* Check header */
758  if (opts_out->binary && opts_out->header_line)
759  ereport(ERROR,
760  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
761  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
762  errmsg("cannot specify %s in BINARY mode", "HEADER")));
763 
764  /* Check quote */
765  if (!opts_out->csv_mode && opts_out->quote != NULL)
766  ereport(ERROR,
767  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
768  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
769  errmsg("COPY %s requires CSV mode", "QUOTE")));
770 
771  if (opts_out->csv_mode && strlen(opts_out->quote) != 1)
772  ereport(ERROR,
773  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
774  errmsg("COPY quote must be a single one-byte character")));
775 
776  if (opts_out->csv_mode && opts_out->delim[0] == opts_out->quote[0])
777  ereport(ERROR,
778  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
779  errmsg("COPY delimiter and quote must be different")));
780 
781  /* Check escape */
782  if (!opts_out->csv_mode && opts_out->escape != NULL)
783  ereport(ERROR,
784  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
785  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
786  errmsg("COPY %s requires CSV mode", "ESCAPE")));
787 
788  if (opts_out->csv_mode && strlen(opts_out->escape) != 1)
789  ereport(ERROR,
790  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
791  errmsg("COPY escape must be a single one-byte character")));
792 
793  /* Check force_quote */
794  if (!opts_out->csv_mode && (opts_out->force_quote || opts_out->force_quote_all))
795  ereport(ERROR,
796  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
797  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
798  errmsg("COPY %s requires CSV mode", "FORCE_QUOTE")));
799  if ((opts_out->force_quote || opts_out->force_quote_all) && is_from)
800  ereport(ERROR,
801  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
802  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
803  second %s is a COPY with direction, e.g. COPY TO */
804  errmsg("COPY %s cannot be used with %s", "FORCE_QUOTE",
805  "COPY FROM")));
806 
807  /* Check force_notnull */
808  if (!opts_out->csv_mode && (opts_out->force_notnull != NIL ||
809  opts_out->force_notnull_all))
810  ereport(ERROR,
811  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
812  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
813  errmsg("COPY %s requires CSV mode", "FORCE_NOT_NULL")));
814  if ((opts_out->force_notnull != NIL || opts_out->force_notnull_all) &&
815  !is_from)
816  ereport(ERROR,
817  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
818  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
819  second %s is a COPY with direction, e.g. COPY TO */
820  errmsg("COPY %s cannot be used with %s", "FORCE_NOT_NULL",
821  "COPY TO")));
822 
823  /* Check force_null */
824  if (!opts_out->csv_mode && (opts_out->force_null != NIL ||
825  opts_out->force_null_all))
826  ereport(ERROR,
827  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
828  /*- translator: %s is the name of a COPY option, e.g. ON_ERROR */
829  errmsg("COPY %s requires CSV mode", "FORCE_NULL")));
830 
831  if ((opts_out->force_null != NIL || opts_out->force_null_all) &&
832  !is_from)
833  ereport(ERROR,
834  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
835  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
836  second %s is a COPY with direction, e.g. COPY TO */
837  errmsg("COPY %s cannot be used with %s", "FORCE_NULL",
838  "COPY TO")));
839 
840  /* Don't allow the delimiter to appear in the null string. */
841  if (strchr(opts_out->null_print, opts_out->delim[0]) != NULL)
842  ereport(ERROR,
843  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
844  /*- translator: %s is the name of a COPY option, e.g. NULL */
845  errmsg("COPY delimiter character must not appear in the %s specification",
846  "NULL")));
847 
848  /* Don't allow the CSV quote char to appear in the null string. */
849  if (opts_out->csv_mode &&
850  strchr(opts_out->null_print, opts_out->quote[0]) != NULL)
851  ereport(ERROR,
852  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
853  /*- translator: %s is the name of a COPY option, e.g. NULL */
854  errmsg("CSV quote character must not appear in the %s specification",
855  "NULL")));
856 
857  /* Check freeze */
858  if (opts_out->freeze && !is_from)
859  ereport(ERROR,
860  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
861  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
862  second %s is a COPY with direction, e.g. COPY TO */
863  errmsg("COPY %s cannot be used with %s", "FREEZE",
864  "COPY TO")));
865 
866  if (opts_out->default_print)
867  {
868  if (!is_from)
869  ereport(ERROR,
870  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
871  /*- translator: first %s is the name of a COPY option, e.g. ON_ERROR,
872  second %s is a COPY with direction, e.g. COPY TO */
873  errmsg("COPY %s cannot be used with %s", "DEFAULT",
874  "COPY TO")));
875 
876  /* Don't allow the delimiter to appear in the default string. */
877  if (strchr(opts_out->default_print, opts_out->delim[0]) != NULL)
878  ereport(ERROR,
879  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
880  /*- translator: %s is the name of a COPY option, e.g. NULL */
881  errmsg("COPY delimiter character must not appear in the %s specification",
882  "DEFAULT")));
883 
884  /* Don't allow the CSV quote char to appear in the default string. */
885  if (opts_out->csv_mode &&
886  strchr(opts_out->default_print, opts_out->quote[0]) != NULL)
887  ereport(ERROR,
888  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
889  /*- translator: %s is the name of a COPY option, e.g. NULL */
890  errmsg("CSV quote character must not appear in the %s specification",
891  "DEFAULT")));
892 
893  /* Don't allow the NULL and DEFAULT string to be the same */
894  if (opts_out->null_print_len == opts_out->default_print_len &&
895  strncmp(opts_out->null_print, opts_out->default_print,
896  opts_out->null_print_len) == 0)
897  ereport(ERROR,
898  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
899  errmsg("NULL specification and DEFAULT specification cannot be the same")));
900  }
901  /* Check on_error */
902  if (opts_out->binary && opts_out->on_error != COPY_ON_ERROR_STOP)
903  ereport(ERROR,
904  (errcode(ERRCODE_SYNTAX_ERROR),
905  errmsg("only ON_ERROR STOP is allowed in BINARY mode")));
906 
907  if (opts_out->reject_limit && !opts_out->on_error)
908  ereport(ERROR,
909  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
910  /*- translator: first and second %s are the names of COPY option, e.g.
911  * ON_ERROR, third is the value of the COPY option, e.g. IGNORE */
912  errmsg("COPY %s requires %s to be set to %s",
913  "REJECT_LIMIT", "ON_ERROR", "IGNORE")));
914 }
static CopyHeaderChoice defGetCopyHeaderChoice(DefElem *def, bool is_from)
Definition: copy.c:329
static int64 defGetCopyRejectLimitOption(DefElem *def)
Definition: copy.c:425
static CopyOnErrorChoice defGetCopyOnErrorChoice(DefElem *def, ParseState *pstate, bool is_from)
Definition: copy.c:393
static CopyLogVerbosityChoice defGetCopyLogVerbosityChoice(DefElem *def, ParseState *pstate)
Definition: copy.c:442
bool defGetBoolean(DefElem *def)
Definition: define.c:107
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
Definition: define.c:384
static void const char * fmt
void * palloc0(Size size)
Definition: mcxt.c:1347
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
#define lfirst_node(type, lc)
Definition: pg_list.h:176
#define pg_char_to_encoding
Definition: pg_wchar.h:629
int default_print_len
Definition: copy.h:72
bool force_notnull_all
Definition: copy.h:80
bool force_quote_all
Definition: copy.h:77
bool freeze
Definition: copy.h:65
bool binary
Definition: copy.h:64
int null_print_len
Definition: copy.h:69
bool convert_selectively
Definition: copy.h:85
CopyLogVerbosityChoice log_verbosity
Definition: copy.h:87
char * quote
Definition: copy.h:74
CopyOnErrorChoice on_error
Definition: copy.h:86
CopyHeaderChoice header_line
Definition: copy.h:67
List * force_quote
Definition: copy.h:76
char * escape
Definition: copy.h:75
char * null_print
Definition: copy.h:68
List * force_null
Definition: copy.h:82
char * delim
Definition: copy.h:73
int64 reject_limit
Definition: copy.h:88
List * convert_select
Definition: copy.h:89
bool force_null_all
Definition: copy.h:83
bool csv_mode
Definition: copy.h:66
int file_encoding
Definition: copy.h:62
char * default_print
Definition: copy.h:71
List * force_notnull
Definition: copy.h:79

References DefElem::arg, CopyFormatOptions::binary, castNode, CopyFormatOptions::convert_select, CopyFormatOptions::convert_selectively, COPY_ON_ERROR_STOP, CopyFormatOptions::csv_mode, CopyFormatOptions::default_print, CopyFormatOptions::default_print_len, defGetBoolean(), defGetCopyHeaderChoice(), defGetCopyLogVerbosityChoice(), defGetCopyOnErrorChoice(), defGetCopyRejectLimitOption(), defGetString(), DefElem::defname, CopyFormatOptions::delim, ereport, errcode(), errmsg(), ERROR, errorConflictingDefElem(), CopyFormatOptions::escape, CopyFormatOptions::file_encoding, fmt, CopyFormatOptions::force_notnull, CopyFormatOptions::force_notnull_all, CopyFormatOptions::force_null, CopyFormatOptions::force_null_all, CopyFormatOptions::force_quote, CopyFormatOptions::force_quote_all, CopyFormatOptions::freeze, CopyFormatOptions::header_line, IsA, lfirst_node, DefElem::location, CopyFormatOptions::log_verbosity, NIL, CopyFormatOptions::null_print, CopyFormatOptions::null_print_len, CopyFormatOptions::on_error, palloc0(), parser_errposition(), pg_char_to_encoding, CopyFormatOptions::quote, and CopyFormatOptions::reject_limit.

Referenced by BeginCopyFrom(), BeginCopyTo(), and file_fdw_validator().