PostgreSQL Source Code  git master
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-2024, 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 
23 
24 static void
25 to_cb(void *data, int len)
26 {
28  (errmsg("COPY TO callback called with data \"%s\" and length %d",
29  (char *) data, len)));
30 }
31 
33 Datum
35 {
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 %lld rows",
46  (long long) processed)));
47 
48  table_close(rel, NoLock);
49 
51 }
uint64 DoCopyTo(CopyToState cstate)
Definition: copyto.c:742
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:350
void EndCopyTo(CopyToState cstate)
Definition: copyto.c:721
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define NOTICE
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
const void size_t len
const void * data
#define NIL
Definition: pg_list.h:68
uintptr_t Datum
Definition: postgres.h:64
#define RelationGetRelid(relation)
Definition: rel.h:505
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
Datum test_copy_to_callback(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC
static void to_cb(void *data, int len)
PG_FUNCTION_INFO_V1(test_copy_to_callback)