/*
 * DefineRule
 *		Execute a CREATE RULE command.
 */
ObjectAddress
DefineRule(RuleStmt *stmt, const char *queryString)
{
	List	   *actions;
	Node	   *whereClause;
	Oid			relId;

	/* Parse analysis. */
	transformRuleStmt(stmt, queryString, &actions, &whereClause);

	/*
	 * Find and lock the relation.  Lock level should match
	 * DefineQueryRewrite.
	 */
	relId = RangeVarGetRelid(stmt->relation, AccessExclusiveLock, false);

	/* ... and execute */
	return DefineQueryRewrite(stmt->rulename,
							  relId,
							  whereClause,
							  stmt->event,
							  stmt->instead,
							  stmt->replace,
							  actions);
}
Esempio n. 2
0
/*
 * DefineRule
 *		Execute a CREATE RULE command.
 */
void
DefineRule(RuleStmt *stmt, const char *queryString)
{
	List	   *actions;
	Node	   *whereClause;
	Oid			relId;

	/* Parse analysis ... */
	transformRuleStmt(stmt, queryString, &actions, &whereClause);

	/* ... find the relation ... */
	relId = RangeVarGetRelid(stmt->relation, false);

	/* ... and execute */
	DefineQueryRewrite(stmt->rulename,
					   relId,
					   whereClause,
					   stmt->event,
					   stmt->instead,
					   stmt->replace,
					   actions);
}