Fix indentation in twophase.c
[pgsql.git] / src / include / commands / copy.h
blob33175868f653af4b9e1156106d5dbd4ada919e4d
1 /*-------------------------------------------------------------------------
3 * copy.h
4 * Definitions for using the POSTGRES copy command.
7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/commands/copy.h
12 *-------------------------------------------------------------------------
14 #ifndef COPY_H
15 #define COPY_H
17 #include "nodes/execnodes.h"
18 #include "nodes/parsenodes.h"
19 #include "parser/parse_node.h"
20 #include "tcop/dest.h"
23 * Represents whether a header line should be present, and whether it must
24 * match the actual names (which implies "true").
26 typedef enum CopyHeaderChoice
28 COPY_HEADER_FALSE = 0,
29 COPY_HEADER_TRUE,
30 COPY_HEADER_MATCH,
31 } CopyHeaderChoice;
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.
38 typedef struct CopyFormatOptions
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 *default_print; /* DEFAULT marker string */
51 int default_print_len; /* length of same */
52 char *delim; /* column delimiter (must be 1 byte) */
53 char *quote; /* CSV quote char (must be 1 byte) */
54 char *escape; /* CSV escape char (must be 1 byte) */
55 List *force_quote; /* list of column names */
56 bool force_quote_all; /* FORCE_QUOTE *? */
57 bool *force_quote_flags; /* per-column CSV FQ flags */
58 List *force_notnull; /* list of column names */
59 bool *force_notnull_flags; /* per-column CSV FNN flags */
60 List *force_null; /* list of column names */
61 bool *force_null_flags; /* per-column CSV FN flags */
62 bool convert_selectively; /* do selective binary conversion? */
63 List *convert_select; /* list of column names (can be NIL) */
64 } CopyFormatOptions;
66 /* These are private in commands/copy[from|to].c */
67 typedef struct CopyFromStateData *CopyFromState;
68 typedef struct CopyToStateData *CopyToState;
70 typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread);
71 typedef void (*copy_data_dest_cb) (void *data, int len);
73 extern void DoCopy(ParseState *pstate, const CopyStmt *stmt,
74 int stmt_location, int stmt_len,
75 uint64 *processed);
77 extern void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options);
78 extern CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *whereClause,
79 const char *filename,
80 bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options);
81 extern void EndCopyFrom(CopyFromState cstate);
82 extern bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
83 Datum *values, bool *nulls);
84 extern bool NextCopyFromRawFields(CopyFromState cstate,
85 char ***fields, int *nfields);
86 extern void CopyFromErrorCallback(void *arg);
88 extern uint64 CopyFrom(CopyFromState cstate);
90 extern DestReceiver *CreateCopyDestReceiver(void);
93 * internal prototypes
95 extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *raw_query,
96 Oid queryRelId, const char *filename, bool is_program,
97 copy_data_dest_cb data_dest_cb, List *attnamelist, List *options);
98 extern void EndCopyTo(CopyToState cstate);
99 extern uint64 DoCopyTo(CopyToState cstate);
100 extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel,
101 List *attnamelist);
103 #endif /* COPY_H */