@@ -1325,95 +1325,67 @@ get_object_address_relobject(ObjectType objtype, List *objname,
13251325	Relation 	relation  =  NULL ;
13261326	int 			nnames ;
13271327	const  char  * depname ;
1328+ 	List 	   * relname ;
1329+ 	Oid 			reloid ;
13281330
13291331	/* Extract name of dependent object. */ 
13301332	depname  =  strVal (llast (objname ));
13311333
13321334	/* Separate relation name from dependent object name. */ 
13331335	nnames  =  list_length (objname );
13341336	if  (nnames  <  2 )
1335- 	{
1336- 		Oid 			reloid ;
1337- 
1338- 		/* 
1339- 		 * For compatibility with very old releases, we sometimes allow users 
1340- 		 * to attempt to specify a rule without mentioning the relation name. 
1341- 		 * If there's only rule by that name in the entire database, this will 
1342- 		 * work.  But objects other than rules don't get this special 
1343- 		 * treatment. 
1344- 		 */ 
1345- 		if  (objtype  !=  OBJECT_RULE )
1346- 			elog (ERROR , "must specify relation and object name" );
1347- 		address .classId  =  RewriteRelationId ;
1348- 		address .objectId  = 
1349- 			get_rewrite_oid_without_relid (depname , & reloid , missing_ok );
1350- 		address .objectSubId  =  0 ;
1351- 
1352- 		/* 
1353- 		 * Caller is expecting to get back the relation, even though we didn't 
1354- 		 * end up using it to find the rule. 
1355- 		 */ 
1356- 		if  (OidIsValid (address .objectId ))
1357- 			relation  =  heap_open (reloid , AccessShareLock );
1358- 	}
1359- 	else 
1360- 	{
1361- 		List 	   * relname ;
1362- 		Oid 			reloid ;
1337+ 		ereport (ERROR ,
1338+ 				(errcode (ERRCODE_SYNTAX_ERROR ),
1339+ 				 errmsg ("must specify relation and object name" )));
13631340
1364- 		 /* Extract relation name and open relation. */ 
1365- 		 relname  =  list_truncate (list_copy (objname ), nnames  -  1 );
1366- 		 relation  =  heap_openrv_extended (makeRangeVarFromNameList (relname ),
1367- 										 AccessShareLock ,
1368- 										 missing_ok );
1341+ 	/* Extract relation name and open relation. */ 
1342+ 	relname  =  list_truncate (list_copy (objname ), nnames  -  1 );
1343+ 	relation  =  heap_openrv_extended (makeRangeVarFromNameList (relname ),
1344+ 									AccessShareLock ,
1345+ 									missing_ok );
13691346
1370- 		 reloid  =  relation  ? RelationGetRelid (relation ) : InvalidOid ;
1347+ 	reloid  =  relation  ? RelationGetRelid (relation ) : InvalidOid ;
13711348
1372- 		switch  (objtype )
1373- 		{
1374- 			case  OBJECT_RULE :
1375- 				address .classId  =  RewriteRelationId ;
1376- 				address .objectId  =  relation  ?
1377- 					get_rewrite_oid (reloid , depname , missing_ok ) : InvalidOid ;
1378- 				address .objectSubId  =  0 ;
1379- 				break ;
1380- 			case  OBJECT_TRIGGER :
1381- 				address .classId  =  TriggerRelationId ;
1382- 				address .objectId  =  relation  ?
1383- 					get_trigger_oid (reloid , depname , missing_ok ) : InvalidOid ;
1384- 				address .objectSubId  =  0 ;
1385- 				break ;
1386- 			case  OBJECT_TABCONSTRAINT :
1387- 				address .classId  =  ConstraintRelationId ;
1388- 				address .objectId  =  relation  ?
1389- 					get_relation_constraint_oid (reloid , depname , missing_ok ) :
1390- 					InvalidOid ;
1391- 				address .objectSubId  =  0 ;
1392- 				break ;
1393- 			case  OBJECT_POLICY :
1394- 				address .classId  =  PolicyRelationId ;
1395- 				address .objectId  =  relation  ?
1396- 					get_relation_policy_oid (reloid , depname , missing_ok ) :
1397- 					InvalidOid ;
1398- 				address .objectSubId  =  0 ;
1399- 				break ;
1400- 			default :
1401- 				elog (ERROR , "unrecognized objtype: %d" , (int ) objtype );
1402- 				/* placate compiler, which doesn't know elog won't return */ 
1403- 				address .classId  =  InvalidOid ;
1404- 				address .objectId  =  InvalidOid ;
1405- 				address .objectSubId  =  0 ;
1406- 		}
1349+ 	switch  (objtype )
1350+ 	{
1351+ 		case  OBJECT_RULE :
1352+ 			address .classId  =  RewriteRelationId ;
1353+ 			address .objectId  =  relation  ?
1354+ 				get_rewrite_oid (reloid , depname , missing_ok ) : InvalidOid ;
1355+ 			address .objectSubId  =  0 ;
1356+ 			break ;
1357+ 		case  OBJECT_TRIGGER :
1358+ 			address .classId  =  TriggerRelationId ;
1359+ 			address .objectId  =  relation  ?
1360+ 				get_trigger_oid (reloid , depname , missing_ok ) : InvalidOid ;
1361+ 			address .objectSubId  =  0 ;
1362+ 			break ;
1363+ 		case  OBJECT_TABCONSTRAINT :
1364+ 			address .classId  =  ConstraintRelationId ;
1365+ 			address .objectId  =  relation  ?
1366+ 				get_relation_constraint_oid (reloid , depname , missing_ok ) :
1367+ 				InvalidOid ;
1368+ 			address .objectSubId  =  0 ;
1369+ 			break ;
1370+ 		case  OBJECT_POLICY :
1371+ 			address .classId  =  PolicyRelationId ;
1372+ 			address .objectId  =  relation  ?
1373+ 				get_relation_policy_oid (reloid , depname , missing_ok ) :
1374+ 				InvalidOid ;
1375+ 			address .objectSubId  =  0 ;
1376+ 			break ;
1377+ 		default :
1378+ 			elog (ERROR , "unrecognized objtype: %d" , (int ) objtype );
1379+ 	}
14071380
1408- 		 /* Avoid relcache leak when object not found. */ 
1409- 		 if  (!OidIsValid (address .objectId ))
1410- 		 {
1411- 			 if  (relation  !=  NULL )
1412- 				 heap_close (relation , AccessShareLock );
1381+ 	/* Avoid relcache leak when object not found. */ 
1382+ 	if  (!OidIsValid (address .objectId ))
1383+ 	{
1384+ 		if  (relation  !=  NULL )
1385+ 			heap_close (relation , AccessShareLock );
14131386
1414- 			relation  =  NULL ;	/* department of accident prevention */ 
1415- 			return  address ;
1416- 		}
1387+ 		relation  =  NULL ;	/* department of accident prevention */ 
1388+ 		return  address ;
14171389	}
14181390
14191391	/* Done. */ 
0 commit comments