PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
copyapi.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * copyapi.h
4 * API for COPY TO/FROM handlers
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/commands/copyapi.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef COPYAPI_H
15#define COPYAPI_H
16
17#include "commands/copy.h"
18
19/*
20 * API structure for a COPY TO format implementation. Note this must be
21 * allocated in a server-lifetime manner, typically as a static const struct.
22 */
23typedef struct CopyToRoutine
24{
25 /*
26 * Set output function information. This callback is called once at the
27 * beginning of COPY TO.
28 *
29 * 'finfo' can be optionally filled to provide the catalog information of
30 * the output function.
31 *
32 * 'atttypid' is the OID of data type used by the relation's attribute.
33 */
34 void (*CopyToOutFunc) (CopyToState cstate, Oid atttypid,
35 FmgrInfo *finfo);
36
37 /*
38 * Start a COPY TO. This callback is called once at the beginning of COPY
39 * TO.
40 *
41 * 'tupDesc' is the tuple descriptor of the relation from where the data
42 * is read.
43 */
44 void (*CopyToStart) (CopyToState cstate, TupleDesc tupDesc);
45
46 /*
47 * Write one row stored in 'slot' to the destination.
48 */
49 void (*CopyToOneRow) (CopyToState cstate, TupleTableSlot *slot);
50
51 /*
52 * End a COPY TO. This callback is called once at the end of COPY TO.
53 */
54 void (*CopyToEnd) (CopyToState cstate);
56
57/*
58 * API structure for a COPY FROM format implementation. Note this must be
59 * allocated in a server-lifetime manner, typically as a static const struct.
60 */
61typedef struct CopyFromRoutine
62{
63 /*
64 * Set input function information. This callback is called once at the
65 * beginning of COPY FROM.
66 *
67 * 'finfo' can be optionally filled to provide the catalog information of
68 * the input function.
69 *
70 * 'typioparam' can be optionally filled to define the OID of the type to
71 * pass to the input function.'atttypid' is the OID of data type used by
72 * the relation's attribute.
73 */
74 void (*CopyFromInFunc) (CopyFromState cstate, Oid atttypid,
75 FmgrInfo *finfo, Oid *typioparam);
76
77 /*
78 * Start a COPY FROM. This callback is called once at the beginning of
79 * COPY FROM.
80 *
81 * 'tupDesc' is the tuple descriptor of the relation where the data needs
82 * to be copied. This can be used for any initialization steps required by
83 * a format.
84 */
85 void (*CopyFromStart) (CopyFromState cstate, TupleDesc tupDesc);
86
87 /*
88 * Read one row from the source and fill *values and *nulls.
89 *
90 * 'econtext' is used to evaluate default expression for each column that
91 * is either not read from the file or is using the DEFAULT option of COPY
92 * FROM. It is NULL if no default values are used.
93 *
94 * Returns false if there are no more tuples to read.
95 */
96 bool (*CopyFromOneRow) (CopyFromState cstate, ExprContext *econtext,
97 Datum *values, bool *nulls);
98
99 /*
100 * End a COPY FROM. This callback is called once at the end of COPY FROM.
101 */
102 void (*CopyFromEnd) (CopyFromState cstate);
104
105#endif /* COPYAPI_H */
static Datum values[MAXATTR]
Definition: bootstrap.c:151
struct CopyFromRoutine CopyFromRoutine
struct CopyToRoutine CopyToRoutine
uintptr_t Datum
Definition: postgres.h:69
unsigned int Oid
Definition: postgres_ext.h:32
void(* CopyFromEnd)(CopyFromState cstate)
Definition: copyapi.h:102
void(* CopyFromInFunc)(CopyFromState cstate, Oid atttypid, FmgrInfo *finfo, Oid *typioparam)
Definition: copyapi.h:74
bool(* CopyFromOneRow)(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
Definition: copyapi.h:96
void(* CopyFromStart)(CopyFromState cstate, TupleDesc tupDesc)
Definition: copyapi.h:85
void(* CopyToOutFunc)(CopyToState cstate, Oid atttypid, FmgrInfo *finfo)
Definition: copyapi.h:34
void(* CopyToOneRow)(CopyToState cstate, TupleTableSlot *slot)
Definition: copyapi.h:49
void(* CopyToEnd)(CopyToState cstate)
Definition: copyapi.h:54
void(* CopyToStart)(CopyToState cstate, TupleDesc tupDesc)
Definition: copyapi.h:44
Definition: fmgr.h:57