From 8a1d81324d741395b8f5964a40370a5b8f374a9c Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Mon, 8 Oct 2018 18:57:20 +0300 Subject: [PATCH] Make get_partition_cooked_key work for tables with no partitions. --- src/pl_funcs.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/pl_funcs.c b/src/pl_funcs.c index 44a5f93f..ea718752 100644 --- a/src/pl_funcs.c +++ b/src/pl_funcs.c @@ -142,22 +142,33 @@ get_partition_key_type_pl(PG_FUNCTION_ARGS) } /* - * Return partition key type. + * Return cooked partition key. */ Datum get_partition_cooked_key_pl(PG_FUNCTION_ARGS) { - Oid relid = PG_GETARG_OID(0); - PartRelationInfo *prel; - Datum res; + /* Values extracted from PATHMAN_CONFIG */ + Datum values[Natts_pathman_config]; + bool isnull[Natts_pathman_config]; + + Oid relid = PG_GETARG_OID(0); + char *expr_cstr; + Node *expr; + char *cooked_cstr; + + /* Check that table is registered in PATHMAN_CONFIG */ + if (!pathman_config_contains_relation(relid, values, isnull, NULL, NULL)) + elog(ERROR, "table \"%s\" is not partitioned", + get_rel_name_or_relid(relid)); - prel = get_pathman_relation_info(relid); - shout_if_prel_is_invalid(relid, prel, PT_ANY); + expr_cstr = TextDatumGetCString(values[Anum_pathman_config_expr - 1]); + expr = cook_partitioning_expression(relid, expr_cstr, NULL); + cooked_cstr = nodeToString(expr); - res = CStringGetTextDatum(nodeToString(prel->expr)); - close_pathman_relation_info(prel); + pfree(expr_cstr); + pfree(expr); - PG_RETURN_TEXT_P(res); + PG_RETURN_TEXT_P(CStringGetTextDatum(cooked_cstr)); } /*