Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38b48da

Browse files
authored
Merge pull request #180 from alexander-kuzmenkov/cooked-key
Make get_partition_cooked_key work for tables with no partitions.
2 parents b33eb4d + 8a1d813 commit 38b48da

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/pl_funcs.c

+20-9
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,33 @@ get_partition_key_type_pl(PG_FUNCTION_ARGS)
142142
}
143143

144144
/*
145-
* Return partition key type.
145+
* Return cooked partition key.
146146
*/
147147
Datum
148148
get_partition_cooked_key_pl(PG_FUNCTION_ARGS)
149149
{
150-
Oid relid = PG_GETARG_OID(0);
151-
PartRelationInfo *prel;
152-
Datum res;
150+
/* Values extracted from PATHMAN_CONFIG */
151+
Datum values[Natts_pathman_config];
152+
bool isnull[Natts_pathman_config];
153+
154+
Oid relid = PG_GETARG_OID(0);
155+
char *expr_cstr;
156+
Node *expr;
157+
char *cooked_cstr;
158+
159+
/* Check that table is registered in PATHMAN_CONFIG */
160+
if (!pathman_config_contains_relation(relid, values, isnull, NULL, NULL))
161+
elog(ERROR, "table \"%s\" is not partitioned",
162+
get_rel_name_or_relid(relid));
153163

154-
prel = get_pathman_relation_info(relid);
155-
shout_if_prel_is_invalid(relid, prel, PT_ANY);
164+
expr_cstr = TextDatumGetCString(values[Anum_pathman_config_expr - 1]);
165+
expr = cook_partitioning_expression(relid, expr_cstr, NULL);
166+
cooked_cstr = nodeToString(expr);
156167

157-
res = CStringGetTextDatum(nodeToString(prel->expr));
158-
close_pathman_relation_info(prel);
168+
pfree(expr_cstr);
169+
pfree(expr);
159170

160-
PG_RETURN_TEXT_P(res);
171+
PG_RETURN_TEXT_P(CStringGetTextDatum(cooked_cstr));
161172
}
162173

163174
/*

0 commit comments

Comments
 (0)