2
0

copy.h 3.7 KB

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