-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_list.c
53 lines (43 loc) · 1.41 KB
/
pg_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
--compile and link it.
gcc -Wextra -I/home/jian/postgres/2023_05_25_beta5421/include/server -fPIC -c /home/jian/postgres_misc/pg_list.c
gcc -shared -o /home/jian/postgres_misc/pg_list.so /home/jian/postgres_misc/pg_list.o
-- use it on SQL level.
CREATE OR REPLACE FUNCTION pg_scratch() RETURNS BOOL
AS '/home/jian/postgres_misc/pg_list', 'pg_scratch' LANGUAGE C STRICT PARALLEL SAFE;
select pg_scratch();
*/
#include "postgres.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "catalog/pg_am_d.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/checksum.h"
#include "storage/bufpage.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/pg_lsn.h"
#include "utils/rel.h"
#include "utils/varlena.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(pg_scratch);
Datum pg_scratch(PG_FUNCTION_ARGS)
{
char *src = "test16.public.a";
text *namlist = cstring_to_text(src);
List *tmp = textToQualifiedNameList(namlist); /*template list*/
ListCell *cell; /* list iterator */
elog(INFO,"list_length:%d",list_length(tmp));
foreach(cell, tmp)
{
String *test = (String *) lfirst(cell);
elog(INFO,"1st string is |%s|", test->sval);
}
PG_RETURN_BOOL(true);
}