forked from citusdata/pg_shard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcitus_metadata_sync.c
60 lines (49 loc) · 1.64 KB
/
citus_metadata_sync.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
54
55
56
57
58
59
60
/*-------------------------------------------------------------------------
*
* citus_metadata_sync.c
*
* This file contains functions to sync pg_shard metadata to the CitusDB
* metadata tables.
*
* Copyright (c) 2014, Citus Data, Inc.
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "c.h"
#include "postgres_ext.h"
#include "citus_metadata_sync.h"
#include "distribution_metadata.h"
#include <stddef.h>
#include "nodes/nodes.h"
#include "nodes/primnodes.h"
#include "utils/builtins.h"
#include "utils/elog.h"
#include "utils/errcodes.h"
/* declarations for dynamic loading */
PG_FUNCTION_INFO_V1(partition_column_to_node_string);
/*
* partition_column_to_node_string is an internal UDF to obtain the textual
* representation of a partition column node (Var), suitable for use within
* CitusDB's metadata tables. This function expects an Oid identifying a table
* previously distributed using pg_shard and will raise an ERROR if the Oid
* is NULL, or does not identify a pg_shard-distributed table.
*/
Datum
partition_column_to_node_string(PG_FUNCTION_ARGS)
{
Oid distributedTableId = InvalidOid;
Var *partitionColumn = NULL;
char *partitionColumnString = NULL;
text *partitionColumnText = NULL;
if (PG_ARGISNULL(0))
{
ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("table_oid cannot be null")));
}
distributedTableId = PG_GETARG_OID(0);
partitionColumn = PartitionColumn(distributedTableId);
partitionColumnString = nodeToString(partitionColumn);
partitionColumnText = cstring_to_text(partitionColumnString);
PG_RETURN_TEXT_P(partitionColumnText);
}