On 2017/06/13 0:29, Peter Eisentraut wrote:
> On 4/24/17 21:22, Amit Langote wrote:
>> Hi Stephen,
>>
>> On 2017/04/11 22:17, Stephen Frost wrote:
>>>> create extension pgrowlocks;
>>>> create view one as select 1;
>>>> select pgrowlocks('one');
>>>> -- ERROR:  could not open file "base/68730/68748": No such file or 
>>>> directory
>>>>
>>>> With the attached patch:
>>>>
>>>> select pgrowlocks('one');
>>>> ERROR:  "one" is not a table, index, materialized view, sequence, or TOAST
>>>> table
>>>
>>> Good point.
>>>
>>> Thanks, I'll see about committing this shortly.
>>
>> Should I add this to the next commitfest (not an open item per se) or will
>> you be committing it?
> 
> What is happening with this?

FWIW, patch seems simple enough to be committed into 10, unless I am
missing something.

Rebased one attached.

Thanks,
Amit
>From 570ae0006fccb9d4a2a53b93169e548050a12c07 Mon Sep 17 00:00:00 2001
From: amit <amitlangot...@gmail.com>
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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to