PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
test_copy_callbacks.c
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------
2
*
3
* test_copy_callbacks.c
4
* Code for testing COPY callbacks.
5
*
6
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
8
*
9
* IDENTIFICATION
10
* src/test/modules/test_copy_callbacks/test_copy_callbacks.c
11
*
12
* -------------------------------------------------------------------------
13
*/
14
15
#include "
postgres.h
"
16
17
#include "
access/table.h
"
18
#include "
commands/copy.h
"
19
#include "
fmgr.h
"
20
#include "
utils/rel.h
"
21
22
PG_MODULE_MAGIC
;
23
24
static
void
25
to_cb
(
void
*
data
,
int
len
)
26
{
27
ereport
(
NOTICE
,
28
(
errmsg
(
"COPY TO callback called with data \"%s\" and length %d"
,
29
(
char
*)
data
,
len
)));
30
}
31
32
PG_FUNCTION_INFO_V1
(
test_copy_to_callback
);
33
Datum
34
test_copy_to_callback
(
PG_FUNCTION_ARGS
)
35
{
36
Relation
rel =
table_open
(
PG_GETARG_OID
(0),
AccessShareLock
);
37
CopyToState
cstate;
38
int64
processed;
39
40
cstate =
BeginCopyTo
(
NULL
, rel,
NULL
,
RelationGetRelid
(rel),
NULL
,
false
,
41
to_cb
,
NIL
,
NIL
);
42
processed =
DoCopyTo
(cstate);
43
EndCopyTo
(cstate);
44
45
ereport
(
NOTICE
, (
errmsg
(
"COPY TO callback has processed %"
PRId64
" rows"
,
46
processed)));
47
48
table_close
(rel,
NoLock
);
49
50
PG_RETURN_VOID
();
51
}
int64
int64_t int64
Definition
c.h:615
DoCopyTo
uint64 DoCopyTo(CopyToState cstate)
Definition
copyto.c:1241
BeginCopyTo
CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *raw_query, Oid queryRelId, const char *filename, bool is_program, copy_data_dest_cb data_dest_cb, List *attnamelist, List *options)
Definition
copyto.c:769
EndCopyTo
void EndCopyTo(CopyToState cstate)
Definition
copyto.c:1220
NOTICE
#define NOTICE
Definition
elog.h:35
ereport
#define ereport(elevel,...)
Definition
elog.h:150
fmgr.h
PG_RETURN_VOID
#define PG_RETURN_VOID()
Definition
fmgr.h:350
PG_GETARG_OID
#define PG_GETARG_OID(n)
Definition
fmgr.h:275
PG_FUNCTION_INFO_V1
#define PG_FUNCTION_INFO_V1(funcname)
Definition
fmgr.h:417
PG_FUNCTION_ARGS
#define PG_FUNCTION_ARGS
Definition
fmgr.h:193
copy.h
NoLock
#define NoLock
Definition
lockdefs.h:34
AccessShareLock
#define AccessShareLock
Definition
lockdefs.h:36
errmsg
static char * errmsg
Definition
oauth_hook_client.c:61
len
const void size_t len
Definition
pg_crc32c_sse42.c:31
data
const void * data
Definition
pg_crc32c_sse42.c:30
NIL
#define NIL
Definition
pg_list.h:68
postgres.h
Datum
uint64_t Datum
Definition
postgres.h:70
fb
static int fb(int x)
Definition
preproc-init.c:92
rel.h
RelationGetRelid
#define RelationGetRelid(relation)
Definition
rel.h:514
CopyToStateData
Definition
copyto.c:72
RelationData
Definition
rel.h:56
table_close
void table_close(Relation relation, LOCKMODE lockmode)
Definition
table.c:126
table_open
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition
table.c:40
table.h
test_copy_to_callback
Datum test_copy_to_callback(PG_FUNCTION_ARGS)
Definition
test_copy_callbacks.c:34
PG_MODULE_MAGIC
PG_MODULE_MAGIC
Definition
test_copy_callbacks.c:22
to_cb
static void to_cb(void *data, int len)
Definition
test_copy_callbacks.c:25
src
test
modules
test_copy_callbacks
test_copy_callbacks.c
Generated on Sun Mar 22 2026 00:13:18 for PostgreSQL Source Code by
1.9.8