PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 must match the actual names
24 * (which implies "true"), and whether it should be present.
25 */
26#define COPY_HEADER_MATCH -1
27#define COPY_HEADER_FALSE 0
28#define COPY_HEADER_TRUE 1
29
30/*
31 * Represents where to save input processing errors. More values to be added
32 * in the future.
33 */
35{
36 COPY_ON_ERROR_STOP = 0, /* immediately throw errors, default */
37 COPY_ON_ERROR_IGNORE, /* ignore errors */
38 COPY_ON_ERROR_SET_NULL, /* set error field to null */
40
41/*
42 * Represents verbosity of logged messages by COPY command.
43 */
45{
46 COPY_LOG_VERBOSITY_SILENT = -1, /* logs none */
47 COPY_LOG_VERBOSITY_DEFAULT = 0, /* logs no additional messages. As this is
48 * the default, assign 0 */
49 COPY_LOG_VERBOSITY_VERBOSE, /* logs additional messages */
51
52/*
53 * Represents the format of the COPY operation.
54 */
62
63/*
64 * A struct to hold COPY options, in a parsed form. All of these are related
65 * to formatting, except for 'freeze', which doesn't really belong here, but
66 * it's expedient to parse it along with all the other options.
67 */
68typedef struct CopyFormatOptions
69{
70 /* parameters from the COPY command */
71 int file_encoding; /* file or remote side's character encoding,
72 * -1 if not specified */
73 CopyFormat format; /* format of the COPY operation */
74 bool freeze; /* freeze rows on loading? */
75 int header_line; /* number of lines to skip or COPY_HEADER_XXX
76 * value (see the above) */
77 char *null_print; /* NULL marker string (server encoding!) */
78 int null_print_len; /* length of same */
79 char *null_print_client; /* same converted to file encoding */
80 char *default_print; /* DEFAULT marker string */
81 int default_print_len; /* length of same */
82 char *delim; /* column delimiter (must be 1 byte) */
83 char *quote; /* CSV quote char (must be 1 byte) */
84 char *escape; /* CSV escape char (must be 1 byte) */
85 List *force_quote; /* list of column names */
86 bool force_quote_all; /* FORCE_QUOTE *? */
87 bool *force_quote_flags; /* per-column CSV FQ flags */
88 List *force_notnull; /* list of column names */
89 bool force_notnull_all; /* FORCE_NOT_NULL *? */
90 bool *force_notnull_flags; /* per-column CSV FNN flags */
91 bool force_array; /* add JSON array decorations */
92 List *force_null; /* list of column names */
93 bool force_null_all; /* FORCE_NULL *? */
94 bool *force_null_flags; /* per-column CSV FN flags */
95 bool convert_selectively; /* do selective binary conversion? */
96 CopyOnErrorChoice on_error; /* what to do when error happened */
97 CopyLogVerbosityChoice log_verbosity; /* verbosity of logged messages */
98 int64 reject_limit; /* maximum tolerable number of errors */
99 List *convert_select; /* list of column names (can be NIL) */
101
102/* These are private in commands/copy[from|to].c */
105
106typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread);
107typedef void (*copy_data_dest_cb) (void *data, int len);
108
109extern void DoCopy(ParseState *pstate, const CopyStmt *stmt,
110 int stmt_location, int stmt_len,
111 uint64 *processed);
112
113extern void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options);
115 const char *filename,
116 bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options);
117extern void EndCopyFrom(CopyFromState cstate);
118extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
119 Datum *values, bool *nulls);
120extern bool NextCopyFromRawFields(CopyFromState cstate,
121 char ***fields, int *nfields);
122extern void CopyFromErrorCallback(void *arg);
123extern char *CopyLimitPrintoutLength(const char *str);
124
125extern uint64 CopyFrom(CopyFromState cstate);
126
128
129/*
130 * internal prototypes
131 */
133 Oid queryRelId, const char *filename, bool is_program,
135extern void EndCopyTo(CopyToState cstate);
136extern uint64 DoCopyTo(CopyToState cstate);
139
140#endif /* COPY_H */
static Datum values[MAXATTR]
Definition bootstrap.c:188
int64_t int64
Definition c.h:615
uint64_t uint64
Definition c.h:619
Datum arg
Definition elog.c:1322
const char * str
char * CopyLimitPrintoutLength(const char *str)
Definition copyfrom.c:335
CopyOnErrorChoice
Definition copy.h:35
@ COPY_ON_ERROR_IGNORE
Definition copy.h:37
@ COPY_ON_ERROR_SET_NULL
Definition copy.h:38
@ COPY_ON_ERROR_STOP
Definition copy.h:36
CopyLogVerbosityChoice
Definition copy.h:45
@ COPY_LOG_VERBOSITY_SILENT
Definition copy.h:46
@ COPY_LOG_VERBOSITY_VERBOSE
Definition copy.h:49
@ COPY_LOG_VERBOSITY_DEFAULT
Definition copy.h:47
uint64 DoCopyTo(CopyToState cstate)
Definition copyto.c:1241
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition copy.c:63
CopyFormat
Definition copy.h:56
@ COPY_FORMAT_CSV
Definition copy.h:59
@ COPY_FORMAT_JSON
Definition copy.h:60
@ COPY_FORMAT_BINARY
Definition copy.h:58
@ COPY_FORMAT_TEXT
Definition copy.h:57
List * CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
Definition copy.c:1048
DestReceiver * CreateCopyDestReceiver(void)
Definition copyto.c:1708
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:1535
struct CopyFromStateData * CopyFromState
Definition copy.h:103
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:769
void(* copy_data_dest_cb)(void *data, int len)
Definition copy.h:107
uint64 CopyFrom(CopyFromState cstate)
Definition copyfrom.c:781
int(* copy_data_source_cb)(void *outbuf, int minread, int maxread)
Definition copy.h:106
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
Definition copy.c:561
void EndCopyFrom(CopyFromState cstate)
Definition copyfrom.c:1942
struct CopyToStateData * CopyToState
Definition copy.h:104
void EndCopyTo(CopyToState cstate)
Definition copyto.c:1220
void CopyFromErrorCallback(void *arg)
Definition copyfrom.c:256
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
bool NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
#define stmt
const void size_t len
const void * data
static char * filename
Definition pg_dumpall.c:133
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
int header_line
Definition copy.h:75
CopyFormat format
Definition copy.h:73
int default_print_len
Definition copy.h:81
bool force_notnull_all
Definition copy.h:89
bool force_quote_all
Definition copy.h:86
int null_print_len
Definition copy.h:78
bool convert_selectively
Definition copy.h:95
CopyLogVerbosityChoice log_verbosity
Definition copy.h:97
char * quote
Definition copy.h:83
CopyOnErrorChoice on_error
Definition copy.h:96
bool force_array
Definition copy.h:91
List * force_quote
Definition copy.h:85
char * escape
Definition copy.h:84
char * null_print
Definition copy.h:77
List * force_null
Definition copy.h:92
char * delim
Definition copy.h:82
int64 reject_limit
Definition copy.h:98
List * convert_select
Definition copy.h:99
bool * force_quote_flags
Definition copy.h:87
bool force_null_all
Definition copy.h:93
bool * force_notnull_flags
Definition copy.h:90
char * null_print_client
Definition copy.h:79
int file_encoding
Definition copy.h:71
bool * force_null_flags
Definition copy.h:94
char * default_print
Definition copy.h:80
List * force_notnull
Definition copy.h:88
Node * whereClause
Definition copyto.c:102
Relation rel
Definition copyto.c:86
copy_data_dest_cb data_dest_cb
Definition copyto.c:99
bool is_program
Definition copyto.c:90
TupleDesc tupDesc
Definition copyto.c:94
Definition pg_list.h:54
Definition nodes.h:135