|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.136 2009/01/27 12:40:15 petere Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.137 2009/05/13 22:32:55 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
15 | 15 | #include "postgres.h"
|
16 | 16 |
|
17 | 17 | #include "access/heapam.h"
|
| 18 | +#include "catalog/catalog.h" |
18 | 19 | #include "catalog/dependency.h"
|
19 | 20 | #include "catalog/indexing.h"
|
20 | 21 | #include "catalog/namespace.h"
|
@@ -242,6 +243,22 @@ DefineQueryRewrite(char *rulename,
|
242 | 243 | */
|
243 | 244 | event_relation = heap_open(event_relid, AccessExclusiveLock);
|
244 | 245 |
|
| 246 | + /* |
| 247 | + * Verify relation is of a type that rules can sensibly be applied to. |
| 248 | + */ |
| 249 | + if (event_relation->rd_rel->relkind != RELKIND_RELATION && |
| 250 | + event_relation->rd_rel->relkind != RELKIND_VIEW) |
| 251 | + ereport(ERROR, |
| 252 | + (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 253 | + errmsg("\"%s\" is not a table or view", |
| 254 | + RelationGetRelationName(event_relation)))); |
| 255 | + |
| 256 | + if (!allowSystemTableMods && IsSystemRelation(event_relation)) |
| 257 | + ereport(ERROR, |
| 258 | + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 259 | + errmsg("permission denied: \"%s\" is a system catalog", |
| 260 | + RelationGetRelationName(event_relation)))); |
| 261 | + |
245 | 262 | /*
|
246 | 263 | * Check user has permission to apply rules to this relation.
|
247 | 264 | */
|
|
0 commit comments