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-2022, 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  * A struct to hold COPY options, in a parsed form. All of these are related
35  * to formatting, except for 'freeze', which doesn't really belong here, but
36  * it's expedient to parse it along with all the other options.
37  */
38 typedef struct CopyFormatOptions
39 {
40  /* parameters from the COPY command */
41  int file_encoding; /* file or remote side's character encoding,
42  * -1 if not specified */
43  bool binary; /* binary format? */
44  bool freeze; /* freeze rows on loading? */
45  bool csv_mode; /* Comma Separated Value format? */
46  CopyHeaderChoice header_line; /* header line? */
47  char *null_print; /* NULL marker string (server encoding!) */
48  int null_print_len; /* length of same */
49  char *null_print_client; /* same converted to file encoding */
50  char *delim; /* column delimiter (must be 1 byte) */
51  char *quote; /* CSV quote char (must be 1 byte) */
52  char *escape; /* CSV escape char (must be 1 byte) */
53  List *force_quote; /* list of column names */
54  bool force_quote_all; /* FORCE_QUOTE *? */
55  bool *force_quote_flags; /* per-column CSV FQ flags */
56  List *force_notnull; /* list of column names */
57  bool *force_notnull_flags; /* per-column CSV FNN flags */
58  List *force_null; /* list of column names */
59  bool *force_null_flags; /* per-column CSV FN flags */
60  bool convert_selectively; /* do selective binary conversion? */
61  List *convert_select; /* list of column names (can be NIL) */
63 
64 /* These are private in commands/copy[from|to].c */
66 typedef struct CopyToStateData *CopyToState;
67 
68 typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread);
69 
70 extern void DoCopy(ParseState *state, const CopyStmt *stmt,
71  int stmt_location, int stmt_len,
72  uint64 *processed);
73 
74 extern void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *ops_out, bool is_from, List *options);
76  const char *filename,
77  bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options);
78 extern void EndCopyFrom(CopyFromState cstate);
79 extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
80  Datum *values, bool *nulls);
81 extern bool NextCopyFromRawFields(CopyFromState cstate,
82  char ***fields, int *nfields);
83 extern void CopyFromErrorCallback(void *arg);
84 
85 extern uint64 CopyFrom(CopyFromState cstate);
86 
88 
89 /*
90  * internal prototypes
91  */
92 extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query,
93  Oid queryRelId, const char *filename, bool is_program,
94  List *attnamelist, List *options);
95 extern void EndCopyTo(CopyToState cstate);
96 extern uint64 DoCopyTo(CopyToState cstate);
97 extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel,
98  List *attnamelist);
99 
100 #endif /* COPY_H */
static Datum values[MAXATTR]
Definition: bootstrap.c:156
struct CopyFormatOptions CopyFormatOptions
List * CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
Definition: copy.c:715
uint64 DoCopyTo(CopyToState cstate)
Definition: copyto.c:770
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:1189
struct CopyFromStateData * CopyFromState
Definition: copy.h:65
void DoCopy(ParseState *state, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:64
uint64 CopyFrom(CopyFromState cstate)
Definition: copyfrom.c:528
int(* copy_data_source_cb)(void *outbuf, int minread, int maxread)
Definition: copy.h:68
void EndCopyFrom(CopyFromState cstate)
Definition: copyfrom.c:1563
struct CopyToStateData * CopyToState
Definition: copy.h:66
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:751
DestReceiver * CreateCopyDestReceiver(void)
Definition: copyto.c:1296
CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query, Oid queryRelId, const char *filename, bool is_program, List *attnamelist, List *options)
Definition: copyto.c:341
void CopyFromErrorCallback(void *arg)
Definition: copyfrom.c:115
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *ops_out, bool is_from, List *options)
Definition: copy.c:398
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
bool NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
void * arg
static char * filename
Definition: pg_dumpall.c:94
uintptr_t Datum
Definition: postgres.h:411
unsigned int Oid
Definition: postgres_ext.h:31
bool force_quote_all
Definition: copy.h:54
bool freeze
Definition: copy.h:44
bool binary
Definition: copy.h:43
int null_print_len
Definition: copy.h:48
bool convert_selectively
Definition: copy.h:60
char * quote
Definition: copy.h:51
CopyHeaderChoice header_line
Definition: copy.h:46
List * force_quote
Definition: copy.h:53
char * escape
Definition: copy.h:52
char * null_print
Definition: copy.h:47
List * force_null
Definition: copy.h:58
char * delim
Definition: copy.h:50
List * convert_select
Definition: copy.h:61
bool * force_quote_flags
Definition: copy.h:55
bool * force_notnull_flags
Definition: copy.h:57
char * null_print_client
Definition: copy.h:49
bool csv_mode
Definition: copy.h:45
int file_encoding
Definition: copy.h:41
bool * force_null_flags
Definition: copy.h:59
List * force_notnull
Definition: copy.h:56
Node * whereClause
Definition: copyto.c:90
Relation rel
Definition: copyto.c:83
bool is_program
Definition: copyto.c:87
Definition: pg_list.h:51
Definition: nodes.h:574
Definition: regguts.h:318