@@ -2333,30 +2333,40 @@ renameatt(RenameStmt *stmt)
23332333 */
23342334static void
23352335rename_constraint_internal (Oid myrelid ,
2336+ Oid mytypid ,
23362337const char * oldconname ,
23372338const char * newconname ,
23382339bool recurse ,
23392340bool recursing ,
23402341int expected_parents )
23412342{
2342- Relation targetrelation ;
2343+ Relation targetrelation = NULL ;
23432344Oid constraintOid ;
23442345HeapTuple tuple ;
23452346Form_pg_constraint con ;
23462347
2347- targetrelation = relation_open (myrelid ,AccessExclusiveLock );
2348- /* don't tell it whether we're recursing; we allow changing typed tables here */
2349- renameatt_check (myrelid ,RelationGetForm (targetrelation ), false);
2348+ AssertArg (!myrelid || !mytypid );
2349+
2350+ if (mytypid )
2351+ {
2352+ constraintOid = get_domain_constraint_oid (mytypid ,oldconname , false);
2353+ }
2354+ else
2355+ {
2356+ targetrelation = relation_open (myrelid ,AccessExclusiveLock );
2357+ /* don't tell it whether we're recursing; we allow changing typed tables here */
2358+ renameatt_check (myrelid ,RelationGetForm (targetrelation ), false);
23502359
2351- constraintOid = get_constraint_oid (myrelid ,oldconname , false);
2360+ constraintOid = get_relation_constraint_oid (myrelid ,oldconname , false);
2361+ }
23522362
23532363tuple = SearchSysCache1 (CONSTROID ,ObjectIdGetDatum (constraintOid ));
23542364if (!HeapTupleIsValid (tuple ))
23552365elog (ERROR ,"cache lookup failed for constraint %u" ,
23562366constraintOid );
23572367con = (Form_pg_constraint )GETSTRUCT (tuple );
23582368
2359- if (con -> contype == CONSTRAINT_CHECK && !con -> conisonly )
2369+ if (myrelid && con -> contype == CONSTRAINT_CHECK && !con -> conisonly )
23602370{
23612371if (recurse )
23622372{
@@ -2376,7 +2386,7 @@ rename_constraint_internal(Oid myrelid,
23762386if (childrelid == myrelid )
23772387continue ;
23782388
2379- rename_constraint_internal (childrelid ,oldconname ,newconname , false, true,numparents );
2389+ rename_constraint_internal (childrelid ,InvalidOid , oldconname ,newconname , false, true,numparents );
23802390}
23812391}
23822392else
@@ -2407,24 +2417,43 @@ rename_constraint_internal(Oid myrelid,
24072417
24082418ReleaseSysCache (tuple );
24092419
2410- relation_close (targetrelation ,NoLock );/* close rel but keep lock */
2420+ if (targetrelation )
2421+ relation_close (targetrelation ,NoLock );/* close rel but keep lock */
24112422}
24122423
24132424void
24142425RenameConstraint (RenameStmt * stmt )
24152426{
2416- Oid relid ;
2427+ Oid relid = InvalidOid ;
2428+ Oid typid = InvalidOid ;
24172429
2418- /* lock level taken here should match rename_constraint_internal */
2419- relid = RangeVarGetRelidExtended (stmt -> relation ,AccessExclusiveLock ,
2420- false, false,
2421- RangeVarCallbackForRenameAttribute ,
2422- NULL );
2430+ if (stmt -> relationType == OBJECT_DOMAIN )
2431+ {
2432+ Relation rel ;
2433+ HeapTuple tup ;
2434+
2435+ typid = typenameTypeId (NULL ,makeTypeNameFromNameList (stmt -> object ));
2436+ rel = heap_open (TypeRelationId ,RowExclusiveLock );
2437+ tup = SearchSysCache1 (TYPEOID ,ObjectIdGetDatum (typid ));
2438+ if (!HeapTupleIsValid (tup ))
2439+ elog (ERROR ,"cache lookup failed for type %u" ,typid );
2440+ checkDomainOwner (tup );
2441+ ReleaseSysCache (tup );
2442+ heap_close (rel ,NoLock );
2443+ }
2444+ else
2445+ {
2446+ /* lock level taken here should match rename_constraint_internal */
2447+ relid = RangeVarGetRelidExtended (stmt -> relation ,AccessExclusiveLock ,
2448+ false, false,
2449+ RangeVarCallbackForRenameAttribute ,
2450+ NULL );
2451+ }
24232452
2424- rename_constraint_internal (relid ,
2453+ rename_constraint_internal (relid ,typid ,
24252454stmt -> subname ,
24262455stmt -> newname ,
2427- interpretInhOption (stmt -> relation -> inhOpt ),/* recursive? */
2456+ stmt -> relation ? interpretInhOption (stmt -> relation -> inhOpt ) : false ,/* recursive? */
24282457 false,/* recursing? */
242924580 /* expected inhcount */ );
24302459}