mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Remove deprecated COMMENT ON RULE syntax
This was only used for allowing upgrades from pre-7.3 instances, which was a long time ago.
This commit is contained in:
@ -1325,6 +1325,8 @@ get_object_address_relobject(ObjectType objtype, List *objname,
|
|||||||
Relation relation = NULL;
|
Relation relation = NULL;
|
||||||
int nnames;
|
int nnames;
|
||||||
const char *depname;
|
const char *depname;
|
||||||
|
List *relname;
|
||||||
|
Oid reloid;
|
||||||
|
|
||||||
/* Extract name of dependent object. */
|
/* Extract name of dependent object. */
|
||||||
depname = strVal(llast(objname));
|
depname = strVal(llast(objname));
|
||||||
@ -1332,88 +1334,58 @@ get_object_address_relobject(ObjectType objtype, List *objname,
|
|||||||
/* Separate relation name from dependent object name. */
|
/* Separate relation name from dependent object name. */
|
||||||
nnames = list_length(objname);
|
nnames = list_length(objname);
|
||||||
if (nnames < 2)
|
if (nnames < 2)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
|
errmsg("must specify relation and object name")));
|
||||||
|
|
||||||
|
/* Extract relation name and open relation. */
|
||||||
|
relname = list_truncate(list_copy(objname), nnames - 1);
|
||||||
|
relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
|
||||||
|
AccessShareLock,
|
||||||
|
missing_ok);
|
||||||
|
|
||||||
|
reloid = relation ? RelationGetRelid(relation) : InvalidOid;
|
||||||
|
|
||||||
|
switch (objtype)
|
||||||
{
|
{
|
||||||
Oid reloid;
|
case OBJECT_RULE:
|
||||||
|
address.classId = RewriteRelationId;
|
||||||
/*
|
address.objectId = relation ?
|
||||||
* For compatibility with very old releases, we sometimes allow users
|
get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
|
||||||
* to attempt to specify a rule without mentioning the relation name.
|
address.objectSubId = 0;
|
||||||
* If there's only rule by that name in the entire database, this will
|
break;
|
||||||
* work. But objects other than rules don't get this special
|
case OBJECT_TRIGGER:
|
||||||
* treatment.
|
address.classId = TriggerRelationId;
|
||||||
*/
|
address.objectId = relation ?
|
||||||
if (objtype != OBJECT_RULE)
|
get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
|
||||||
elog(ERROR, "must specify relation and object name");
|
address.objectSubId = 0;
|
||||||
address.classId = RewriteRelationId;
|
break;
|
||||||
address.objectId =
|
case OBJECT_TABCONSTRAINT:
|
||||||
get_rewrite_oid_without_relid(depname, &reloid, missing_ok);
|
address.classId = ConstraintRelationId;
|
||||||
address.objectSubId = 0;
|
address.objectId = relation ?
|
||||||
|
get_relation_constraint_oid(reloid, depname, missing_ok) :
|
||||||
/*
|
InvalidOid;
|
||||||
* Caller is expecting to get back the relation, even though we didn't
|
address.objectSubId = 0;
|
||||||
* end up using it to find the rule.
|
break;
|
||||||
*/
|
case OBJECT_POLICY:
|
||||||
if (OidIsValid(address.objectId))
|
address.classId = PolicyRelationId;
|
||||||
relation = heap_open(reloid, AccessShareLock);
|
address.objectId = relation ?
|
||||||
|
get_relation_policy_oid(reloid, depname, missing_ok) :
|
||||||
|
InvalidOid;
|
||||||
|
address.objectSubId = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
elog(ERROR, "unrecognized objtype: %d", (int) objtype);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
/* Avoid relcache leak when object not found. */
|
||||||
|
if (!OidIsValid(address.objectId))
|
||||||
{
|
{
|
||||||
List *relname;
|
if (relation != NULL)
|
||||||
Oid reloid;
|
heap_close(relation, AccessShareLock);
|
||||||
|
|
||||||
/* Extract relation name and open relation. */
|
relation = NULL; /* department of accident prevention */
|
||||||
relname = list_truncate(list_copy(objname), nnames - 1);
|
return address;
|
||||||
relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
|
|
||||||
AccessShareLock,
|
|
||||||
missing_ok);
|
|
||||||
|
|
||||||
reloid = relation ? RelationGetRelid(relation) : InvalidOid;
|
|
||||||
|
|
||||||
switch (objtype)
|
|
||||||
{
|
|
||||||
case OBJECT_RULE:
|
|
||||||
address.classId = RewriteRelationId;
|
|
||||||
address.objectId = relation ?
|
|
||||||
get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
|
|
||||||
address.objectSubId = 0;
|
|
||||||
break;
|
|
||||||
case OBJECT_TRIGGER:
|
|
||||||
address.classId = TriggerRelationId;
|
|
||||||
address.objectId = relation ?
|
|
||||||
get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
|
|
||||||
address.objectSubId = 0;
|
|
||||||
break;
|
|
||||||
case OBJECT_TABCONSTRAINT:
|
|
||||||
address.classId = ConstraintRelationId;
|
|
||||||
address.objectId = relation ?
|
|
||||||
get_relation_constraint_oid(reloid, depname, missing_ok) :
|
|
||||||
InvalidOid;
|
|
||||||
address.objectSubId = 0;
|
|
||||||
break;
|
|
||||||
case OBJECT_POLICY:
|
|
||||||
address.classId = PolicyRelationId;
|
|
||||||
address.objectId = relation ?
|
|
||||||
get_relation_policy_oid(reloid, depname, missing_ok) :
|
|
||||||
InvalidOid;
|
|
||||||
address.objectSubId = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
elog(ERROR, "unrecognized objtype: %d", (int) objtype);
|
|
||||||
/* placate compiler, which doesn't know elog won't return */
|
|
||||||
address.classId = InvalidOid;
|
|
||||||
address.objectId = InvalidOid;
|
|
||||||
address.objectSubId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Avoid relcache leak when object not found. */
|
|
||||||
if (!OidIsValid(address.objectId))
|
|
||||||
{
|
|
||||||
if (relation != NULL)
|
|
||||||
heap_close(relation, AccessShareLock);
|
|
||||||
|
|
||||||
relation = NULL; /* department of accident prevention */
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done. */
|
/* Done. */
|
||||||
|
@ -6283,16 +6283,6 @@ CommentStmt:
|
|||||||
n->comment = $8;
|
n->comment = $8;
|
||||||
$$ = (Node *) n;
|
$$ = (Node *) n;
|
||||||
}
|
}
|
||||||
| COMMENT ON RULE name IS comment_text
|
|
||||||
{
|
|
||||||
/* Obsolete syntax supported for awhile for compatibility */
|
|
||||||
CommentStmt *n = makeNode(CommentStmt);
|
|
||||||
n->objtype = OBJECT_RULE;
|
|
||||||
n->objname = list_make1(makeString($4));
|
|
||||||
n->objargs = NIL;
|
|
||||||
n->comment = $6;
|
|
||||||
$$ = (Node *) n;
|
|
||||||
}
|
|
||||||
| COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
|
| COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
|
||||||
{
|
{
|
||||||
CommentStmt *n = makeNode(CommentStmt);
|
CommentStmt *n = makeNode(CommentStmt);
|
||||||
|
@ -114,58 +114,3 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
|
|||||||
ReleaseSysCache(tuple);
|
ReleaseSysCache(tuple);
|
||||||
return ruleoid;
|
return ruleoid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Find rule oid, given only a rule name but no rel OID.
|
|
||||||
*
|
|
||||||
* If there's more than one, it's an error. If there aren't any, that's an
|
|
||||||
* error, too. In general, this should be avoided - it is provided to support
|
|
||||||
* syntax that is compatible with pre-7.3 versions of PG, where rule names
|
|
||||||
* were unique across the entire database.
|
|
||||||
*/
|
|
||||||
Oid
|
|
||||||
get_rewrite_oid_without_relid(const char *rulename,
|
|
||||||
Oid *reloid, bool missing_ok)
|
|
||||||
{
|
|
||||||
Relation RewriteRelation;
|
|
||||||
HeapScanDesc scanDesc;
|
|
||||||
ScanKeyData scanKeyData;
|
|
||||||
HeapTuple htup;
|
|
||||||
Oid ruleoid;
|
|
||||||
|
|
||||||
/* Search pg_rewrite for such a rule */
|
|
||||||
ScanKeyInit(&scanKeyData,
|
|
||||||
Anum_pg_rewrite_rulename,
|
|
||||||
BTEqualStrategyNumber, F_NAMEEQ,
|
|
||||||
CStringGetDatum(rulename));
|
|
||||||
|
|
||||||
RewriteRelation = heap_open(RewriteRelationId, AccessShareLock);
|
|
||||||
scanDesc = heap_beginscan_catalog(RewriteRelation, 1, &scanKeyData);
|
|
||||||
|
|
||||||
htup = heap_getnext(scanDesc, ForwardScanDirection);
|
|
||||||
if (!HeapTupleIsValid(htup))
|
|
||||||
{
|
|
||||||
if (!missing_ok)
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
||||||
errmsg("rule \"%s\" does not exist", rulename)));
|
|
||||||
ruleoid = InvalidOid;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ruleoid = HeapTupleGetOid(htup);
|
|
||||||
if (reloid != NULL)
|
|
||||||
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
|
|
||||||
|
|
||||||
htup = heap_getnext(scanDesc, ForwardScanDirection);
|
|
||||||
if (HeapTupleIsValid(htup))
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
|
||||||
errmsg("there are multiple rules named \"%s\"", rulename),
|
|
||||||
errhint("Specify a relation name as well as a rule name.")));
|
|
||||||
}
|
|
||||||
heap_endscan(scanDesc);
|
|
||||||
heap_close(RewriteRelation, AccessShareLock);
|
|
||||||
|
|
||||||
return ruleoid;
|
|
||||||
}
|
|
||||||
|
@ -22,7 +22,5 @@ extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName);
|
|||||||
extern void SetRelationRuleStatus(Oid relationId, bool relHasRules);
|
extern void SetRelationRuleStatus(Oid relationId, bool relHasRules);
|
||||||
|
|
||||||
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok);
|
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok);
|
||||||
extern Oid get_rewrite_oid_without_relid(const char *rulename,
|
|
||||||
Oid *relid, bool missing_ok);
|
|
||||||
|
|
||||||
#endif /* REWRITESUPPORT_H */
|
#endif /* REWRITESUPPORT_H */
|
||||||
|
@ -19,5 +19,5 @@ COMMENT ON FUNCTION c_function_test() IS 'FUNCTION test';
|
|||||||
ERROR: function c_function_test() does not exist
|
ERROR: function c_function_test() does not exist
|
||||||
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
|
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
|
||||||
NOTICE: DDL test: type simple, tag COMMENT
|
NOTICE: DDL test: type simple, tag COMMENT
|
||||||
COMMENT ON RULE rule_1 IS 'RULE test';
|
COMMENT ON RULE rule_1 ON datatype_table IS 'RULE test';
|
||||||
NOTICE: DDL test: type simple, tag COMMENT
|
NOTICE: DDL test: type simple, tag COMMENT
|
||||||
|
@ -11,4 +11,4 @@ COMMENT ON TABLE datatype_table IS 'This table should contain all native datatyp
|
|||||||
COMMENT ON VIEW datatype_view IS 'This is a view';
|
COMMENT ON VIEW datatype_view IS 'This is a view';
|
||||||
COMMENT ON FUNCTION c_function_test() IS 'FUNCTION test';
|
COMMENT ON FUNCTION c_function_test() IS 'FUNCTION test';
|
||||||
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
|
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
|
||||||
COMMENT ON RULE rule_1 IS 'RULE test';
|
COMMENT ON RULE rule_1 ON datatype_table IS 'RULE test';
|
||||||
|
@ -214,8 +214,8 @@ WARNING: error for operator family,{addr_nsp,zwei},{}: access method "addr_nsp"
|
|||||||
WARNING: error for operator family,{addr_nsp,zwei},{integer}: access method "addr_nsp" does not exist
|
WARNING: error for operator family,{addr_nsp,zwei},{integer}: access method "addr_nsp" does not exist
|
||||||
WARNING: error for operator family,{eins,zwei,drei},{}: access method "eins" does not exist
|
WARNING: error for operator family,{eins,zwei,drei},{}: access method "eins" does not exist
|
||||||
WARNING: error for operator family,{eins,zwei,drei},{integer}: access method "eins" does not exist
|
WARNING: error for operator family,{eins,zwei,drei},{integer}: access method "eins" does not exist
|
||||||
WARNING: error for rule,{eins},{}: rule "eins" does not exist
|
WARNING: error for rule,{eins},{}: must specify relation and object name
|
||||||
WARNING: error for rule,{eins},{integer}: rule "eins" does not exist
|
WARNING: error for rule,{eins},{integer}: must specify relation and object name
|
||||||
WARNING: error for rule,{addr_nsp,zwei},{}: relation "addr_nsp" does not exist
|
WARNING: error for rule,{addr_nsp,zwei},{}: relation "addr_nsp" does not exist
|
||||||
WARNING: error for rule,{addr_nsp,zwei},{integer}: relation "addr_nsp" does not exist
|
WARNING: error for rule,{addr_nsp,zwei},{integer}: relation "addr_nsp" does not exist
|
||||||
WARNING: error for rule,{eins,zwei,drei},{}: schema "eins" does not exist
|
WARNING: error for rule,{eins,zwei,drei},{}: schema "eins" does not exist
|
||||||
|
Reference in New Issue
Block a user