bool do_refresh = false;
DestReceiver *dest;
ObjectAddress address;
- List *rewritten;
- PlannedStmt *plan;
- QueryDesc *queryDesc;
/* Check if the relation exists or not */
if (CreateTableAsRelExists(stmt))
* from running the planner before all dependencies are set up.
*/
address = create_ctas_nodata(query->targetList, into);
+
+ /*
+ * For materialized views, reuse the REFRESH logic, which locks down
+ * security-restricted operations and restricts the search_path. This
+ * reduces the chance that a subsequent refresh will fail.
+ */
+ if (do_refresh)
+ RefreshMatViewByOid(address.objectId, true, false, false,
+ pstate->p_sourcetext, qc);
+
}
else
{
+ List *rewritten;
+ PlannedStmt *plan;
+ QueryDesc *queryDesc;
+
+ Assert(!is_matview);
+
/*
* Parse analysis was done already, but we still have to run the rule
* rewriter. We do not do AcquireRewriteLocks: we assume the query
/* SELECT should never rewrite to more or less than one SELECT query */
if (list_length(rewritten) != 1)
- elog(ERROR, "unexpected rewrite result for %s",
- is_matview ? "CREATE MATERIALIZED VIEW" :
- "CREATE TABLE AS SELECT");
+ elog(ERROR, "unexpected rewrite result for CREATE TABLE AS SELECT");
query = linitial_node(Query, rewritten);
Assert(query->commandType == CMD_SELECT);
PopActiveSnapshot();
}
- /*
- * For materialized views, reuse the REFRESH logic, which locks down
- * security-restricted operations and restricts the search_path. This
- * reduces the chance that a subsequent refresh will fail.
- */
- if (do_refresh)
- {
- RefreshMatViewByOid(address.objectId, true, false, false,
- pstate->p_sourcetext, qc);
- }
-
return address;
}