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