Skip to content

Make get_partition_cooked_key work for tables with no partitions. #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/pl_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/*
Expand Down