From 570ae0006fccb9d4a2a53b93169e548050a12c07 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 11 Apr 2017 16:59:03 +0900 Subject: [PATCH] Add relkind check to pgrowlocks --- contrib/pgrowlocks/pgrowlocks.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c index 00e2015c5c..a1ee7f8034 100644 --- a/contrib/pgrowlocks/pgrowlocks.c +++ b/contrib/pgrowlocks/pgrowlocks.c @@ -66,6 +66,8 @@ typedef struct #define Atnum_modes 4 #define Atnum_pids 5 +static void check_relation_relkind(Relation rel); + Datum pgrowlocks(PG_FUNCTION_ARGS) { @@ -112,6 +114,9 @@ pgrowlocks(PG_FUNCTION_ARGS) aclcheck_error(aclresult, ACL_KIND_CLASS, RelationGetRelationName(rel)); + /* Only some relkinds contain rows */ + check_relation_relkind(rel); + scan = heap_beginscan(rel, GetActiveSnapshot(), 0, NULL); mydata = palloc(sizeof(*mydata)); mydata->rel = rel; @@ -298,3 +303,21 @@ pgrowlocks(PG_FUNCTION_ARGS) SRF_RETURN_DONE(funcctx); } + +/* + * check_relation_relkind - convenience routine to check that relation + * is of the relkind supported by the callers + */ +static void +check_relation_relkind(Relation rel) +{ + if (rel->rd_rel->relkind != RELKIND_RELATION && + rel->rd_rel->relkind != RELKIND_INDEX && + rel->rd_rel->relkind != RELKIND_MATVIEW && + rel->rd_rel->relkind != RELKIND_SEQUENCE && + rel->rd_rel->relkind != RELKIND_TOASTVALUE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a table, index, materialized view, sequence, or TOAST table", + RelationGetRelationName(rel)))); +} -- 2.11.0