PostgreSQL Source Code  git master
copy.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * copy.h
4  * Definitions for using the POSTGRES copy command.
5  *
6  *
7  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/commands/copy.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef COPY_H
15 #define COPY_H
16 
17 #include "nodes/execnodes.h"
18 #include "nodes/parsenodes.h"
19 #include "parser/parse_node.h"
20 #include "tcop/dest.h"
21 
22 /*
23  * Represents whether a header line should be present, and whether it must
24  * match the actual names (which implies "true").
25  */
26 typedef enum CopyHeaderChoice
27 {
32 
33 /*
34  * Represents where to save input processing errors. More values to be added
35  * in the future.
36  */
37 typedef enum CopyOnErrorChoice
38 {
39  COPY_ON_ERROR_STOP = 0, /* immediately throw errors, default */
40  COPY_ON_ERROR_IGNORE, /* ignore errors */
42 
43 /*
44  * Represents verbosity of logged messages by COPY command.
45  */
47 {
48  COPY_LOG_VERBOSITY_SILENT = -1, /* logs none */
49  COPY_LOG_VERBOSITY_DEFAULT = 0, /* logs no additional messages. As this is
50  * the default, assign 0 */
51  COPY_LOG_VERBOSITY_VERBOSE, /* logs additional messages */
53 
54 /*
55  * A struct to hold COPY options, in a parsed form. All of these are related
56  * to formatting, except for 'freeze', which doesn't really belong here, but
57  * it's expedient to parse it along with all the other options.
58  */
59 typedef struct CopyFormatOptions
60 {
61  /* parameters from the COPY command */
62  int file_encoding; /* file or remote side's character encoding,
63  * -1 if not specified */
64  bool binary; /* binary format? */
65  bool freeze; /* freeze rows on loading? */
66  bool csv_mode; /* Comma Separated Value format? */
67  CopyHeaderChoice header_line; /* header line? */
68  char *null_print; /* NULL marker string (server encoding!) */
69  int null_print_len; /* length of same */
70  char *null_print_client; /* same converted to file encoding */
71  char *default_print; /* DEFAULT marker string */
72  int default_print_len; /* length of same */
73  char *delim; /* column delimiter (must be 1 byte) */
74  char *quote; /* CSV quote char (must be 1 byte) */
75  char *escape; /* CSV escape char (must be 1 byte) */
76  List *force_quote; /* list of column names */
77  bool force_quote_all; /* FORCE_QUOTE *? */
78  bool *force_quote_flags; /* per-column CSV FQ flags */
79  List *force_notnull; /* list of column names */
80  bool force_notnull_all; /* FORCE_NOT_NULL *? */
81  bool *force_notnull_flags; /* per-column CSV FNN flags */
82  List *force_null; /* list of column names */
83  bool force_null_all; /* FORCE_NULL *? */
84  bool *force_null_flags; /* per-column CSV FN flags */
85  bool convert_selectively; /* do selective binary conversion? */
86  CopyOnErrorChoice on_error; /* what to do when error happened */
87  CopyLogVerbosityChoice log_verbosity; /* verbosity of logged messages */
88  int64 reject_limit; /* maximum tolerable number of errors */
89  List *convert_select; /* list of column names (can be NIL) */
91 
92 /* These are private in commands/copy[from|to].c */
94 typedef struct CopyToStateData *CopyToState;
95 
96 typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread);
97 typedef void (*copy_data_dest_cb) (void *data, int len);
98 
99 extern void DoCopy(ParseState *pstate, const CopyStmt *stmt,
100  int stmt_location, int stmt_len,
101  uint64 *processed);
102 
103 extern void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options);
105  const char *filename,
106  bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options);
107 extern void EndCopyFrom(CopyFromState cstate);
108 extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
109  Datum *values, bool *nulls);
110 extern bool NextCopyFromRawFields(CopyFromState cstate,
111  char ***fields, int *nfields);
112 extern void CopyFromErrorCallback(void *arg);
113 extern char *CopyLimitPrintoutLength(const char *str);
114 
115 extern uint64 CopyFrom(CopyFromState cstate);
116 
118 
119 /*
120  * internal prototypes
121  */
122 extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *raw_query,
123  Oid queryRelId, const char *filename, bool is_program,
125 extern void EndCopyTo(CopyToState cstate);
126 extern uint64 DoCopyTo(CopyToState cstate);
127 extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel,
128  List *attnamelist);
129 
130 #endif /* COPY_H */
static Datum values[MAXATTR]
Definition: bootstrap.c:150
const char * str
struct CopyFormatOptions CopyFormatOptions
CopyOnErrorChoice
Definition: copy.h:38
@ COPY_ON_ERROR_IGNORE
Definition: copy.h:40
@ COPY_ON_ERROR_STOP
Definition: copy.h:39
List * CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
Definition: copy.c:931
char * CopyLimitPrintoutLength(const char *str)
Definition: copyfrom.c:194
CopyLogVerbosityChoice
Definition: copy.h:47
@ COPY_LOG_VERBOSITY_SILENT
Definition: copy.h:48
@ COPY_LOG_VERBOSITY_VERBOSE
Definition: copy.h:51
@ COPY_LOG_VERBOSITY_DEFAULT
Definition: copy.h:49
uint64 DoCopyTo(CopyToState cstate)
Definition: copyto.c:747
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:62
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
struct CopyFromStateData * CopyFromState
Definition: copy.h:93
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(* copy_data_dest_cb)(void *data, int len)
Definition: copy.h:97
uint64 CopyFrom(CopyFromState cstate)
Definition: copyfrom.c:640
int(* copy_data_source_cb)(void *outbuf, int minread, int maxread)
Definition: copy.h:96
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
Definition: copy.c:482
void EndCopyFrom(CopyFromState cstate)
Definition: copyfrom.c:1802
struct CopyToStateData * CopyToState
Definition: copy.h:94
CopyHeaderChoice
Definition: copy.h:27
@ COPY_HEADER_TRUE
Definition: copy.h:29
@ COPY_HEADER_FALSE
Definition: copy.h:28
@ COPY_HEADER_MATCH
Definition: copy.h:30
void EndCopyTo(CopyToState cstate)
Definition: copyto.c:726
DestReceiver * CreateCopyDestReceiver(void)
Definition: copyto.c:1276
void CopyFromErrorCallback(void *arg)
Definition: copyfrom.c:115
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
bool NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
#define stmt
Definition: indent_codes.h:59
void * arg
const void size_t len
const void * data
static char * filename
Definition: pg_dumpall.c:119
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
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_quote_flags
Definition: copy.h:78
bool force_null_all
Definition: copy.h:83
bool * force_notnull_flags
Definition: copy.h:81
char * null_print_client
Definition: copy.h:70
bool csv_mode
Definition: copy.h:66
int file_encoding
Definition: copy.h:62
bool * force_null_flags
Definition: copy.h:84
char * default_print
Definition: copy.h:71
List * force_notnull
Definition: copy.h:79
Node * whereClause
Definition: copyto.c:85
Relation rel
Definition: copyto.c:77
copy_data_dest_cb data_dest_cb
Definition: copyto.c:82
bool is_program
Definition: copyto.c:81
Definition: pg_list.h:54
Definition: nodes.h:129