8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.67 2002/03/31 06:26 :30 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.68 2002/03/31 07:49 :30 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -69,8 +69,8 @@ static void update_ri_trigger_args(Oid relid,
69
69
*/
70
70
void
71
71
renameatt (Oid relid ,
72
- char * oldattname ,
73
- char * newattname ,
72
+ const char * oldattname ,
73
+ const char * newattname ,
74
74
bool recurse )
75
75
{
76
76
Relation targetrelation ;
@@ -250,51 +250,36 @@ renameatt(Oid relid,
250
250
* renamerel - change the name of a relation
251
251
*/
252
252
void
253
- renamerel (const RangeVar * relation , const char * newrelname )
253
+ renamerel (Oid relid , const char * newrelname )
254
254
{
255
255
Relation targetrelation ;
256
256
Relation relrelation ; /* for RELATION relation */
257
257
HeapTuple reltup ;
258
258
Oid namespaceId ;
259
- Oid reloid ;
260
259
char relkind ;
261
260
bool relhastriggers ;
262
261
Relation irelations [Num_pg_class_indices ];
263
262
264
- if (!allowSystemTableMods && IsSystemRelationName (relation -> relname ))
265
- elog (ERROR , "renamerel: system relation \"%s\" may not be renamed" ,
266
- relation -> relname );
267
-
268
- if (!allowSystemTableMods && IsSystemRelationName (newrelname ))
269
- elog (ERROR , "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs" ,
270
- newrelname );
271
-
272
263
/*
273
264
* Grab an exclusive lock on the target table or index, which we will
274
265
* NOT release until end of transaction.
275
266
*/
276
- targetrelation = relation_openrv ( relation , AccessExclusiveLock );
267
+ targetrelation = relation_open ( relid , AccessExclusiveLock );
277
268
278
269
namespaceId = RelationGetNamespace (targetrelation );
279
- reloid = RelationGetRelid (targetrelation );
280
- relkind = targetrelation -> rd_rel -> relkind ;
281
- relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
282
270
283
- /*
284
- * Close rel, but keep exclusive lock!
285
- */
286
- relation_close (targetrelation , NoLock );
271
+ /* Validity checks */
272
+ if (!allowSystemTableMods &&
273
+ IsSystemRelationName (RelationGetRelationName (targetrelation )))
274
+ elog (ERROR , "renamerel: system relation \"%s\" may not be renamed" ,
275
+ RelationGetRelationName (targetrelation ));
287
276
288
- /*
289
- * Flush the relcache entry (easier than trying to change it at
290
- * exactly the right instant). It'll get rebuilt on next access to
291
- * relation.
292
- *
293
- * XXX What if relation is myxactonly?
294
- *
295
- * XXX this is probably not necessary anymore?
296
- */
297
- RelationIdInvalidateRelationCacheByRelationId (reloid );
277
+ if (!allowSystemTableMods && IsSystemRelationName (newrelname ))
278
+ elog (ERROR , "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs" ,
279
+ newrelname );
280
+
281
+ relkind = targetrelation -> rd_rel -> relkind ;
282
+ relhastriggers = (targetrelation -> rd_rel -> reltriggers > 0 );
298
283
299
284
/*
300
285
* Find relation's pg_class tuple, and make sure newrelname isn't in
@@ -303,11 +288,11 @@ renamerel(const RangeVar *relation, const char *newrelname)
303
288
relrelation = heap_openr (RelationRelationName , RowExclusiveLock );
304
289
305
290
reltup = SearchSysCacheCopy (RELOID ,
306
- PointerGetDatum (reloid ),
291
+ PointerGetDatum (relid ),
307
292
0 , 0 , 0 );
308
293
if (!HeapTupleIsValid (reltup ))
309
294
elog (ERROR , "renamerel: relation \"%s\" does not exist" ,
310
- relation -> relname );
295
+ RelationGetRelationName ( targetrelation ) );
311
296
312
297
if (get_relname_relid (newrelname , namespaceId ) != InvalidOid )
313
298
elog (ERROR , "renamerel: relation \"%s\" exists" , newrelname );
@@ -332,7 +317,8 @@ renamerel(const RangeVar *relation, const char *newrelname)
332
317
* Also rename the associated type, if any.
333
318
*/
334
319
if (relkind != RELKIND_INDEX )
335
- TypeRename (relation -> relname , namespaceId , newrelname );
320
+ TypeRename (RelationGetRelationName (targetrelation ), namespaceId ,
321
+ newrelname );
336
322
337
323
/*
338
324
* If it's a view, must also rename the associated ON SELECT rule.
@@ -342,7 +328,7 @@ renamerel(const RangeVar *relation, const char *newrelname)
342
328
char * oldrulename ,
343
329
* newrulename ;
344
330
345
- oldrulename = MakeRetrieveViewRuleName (relation -> relname );
331
+ oldrulename = MakeRetrieveViewRuleName (RelationGetRelationName ( targetrelation ) );
346
332
newrulename = MakeRetrieveViewRuleName (newrelname );
347
333
RenameRewriteRule (oldrulename , newrulename );
348
334
}
@@ -353,14 +339,21 @@ renamerel(const RangeVar *relation, const char *newrelname)
353
339
if (relhastriggers )
354
340
{
355
341
/* update tgargs where relname is primary key */
356
- update_ri_trigger_args (reloid ,
357
- relation -> relname , newrelname ,
342
+ update_ri_trigger_args (relid ,
343
+ RelationGetRelationName (targetrelation ),
344
+ newrelname ,
358
345
false, true);
359
346
/* update tgargs where relname is foreign key */
360
- update_ri_trigger_args (reloid ,
361
- relation -> relname , newrelname ,
347
+ update_ri_trigger_args (relid ,
348
+ RelationGetRelationName (targetrelation ),
349
+ newrelname ,
362
350
true, true);
363
351
}
352
+
353
+ /*
354
+ * Close rel, but keep exclusive lock!
355
+ */
356
+ relation_close (targetrelation , NoLock );
364
357
}
365
358
366
359
/*
0 commit comments