summaryrefslogtreecommitdiffstats
path: root/src/backend/rewrite
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/rewrite')
-rw-r--r--src/backend/rewrite/rewriteDefine.c6
-rw-r--r--src/backend/rewrite/rewriteHandler.c6
2 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index a354969..6c05a5b 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -29,6 +29,7 @@
#include "catalog/pg_rewrite.h"
#include "catalog/storage.h"
#include "commands/policy.h"
+#include "commands/tablecmds.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_utilcmd.h"
@@ -422,6 +423,9 @@ DefineQueryRewrite(const char *rulename,
* whole business of converting relations to views is just an obsolete
* kluge to allow dump/reload of views that participate in circular
* dependencies.)
+ *
+ * Also ensure the relation isn't being manipulated in any outer SQL
+ * command of our own session.
*/
if (event_relation->rd_rel->relkind != RELKIND_VIEW &&
event_relation->rd_rel->relkind != RELKIND_MATVIEW)
@@ -430,6 +434,8 @@ DefineQueryRewrite(const char *rulename,
Snapshot snapshot;
TupleTableSlot *slot;
+ CheckTableNotInUse(event_relation, "CREATE RULE");
+
if (event_relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 9584995..e678f34 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -1080,9 +1080,9 @@ process_matched_tle(TargetEntry *src_tle,
* resulting in each assignment containing a CoerceToDomain node over a
* FieldStore or SubscriptingRef. These should have matching target
* domains, so we strip them and reconstitute a single CoerceToDomain over
- * the combined FieldStore/SubscriptingRef nodes. (Notice that this has the
- * result that the domain's checks are applied only after we do all the
- * field or element updates, not after each one. This is arguably desirable.)
+ * the combined FieldStore/SubscriptingRef nodes. (Notice that this has
+ * the result that the domain's checks are applied only after we do all
+ * the field or element updates, not after each one. This is desirable.)
*----------
*/
src_expr = (Node *) src_tle->expr;