|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.101 2000/09/1204:49:06 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.102 2000/09/1205:09:43 momjian Exp $ |
12 | 12 | *
|
13 | 13 | * NOTES
|
14 | 14 | * The PerformAddAttribute() code, like most of the relation
|
|
47 | 47 | #include"utils/temprel.h"
|
48 | 48 | #include"executor/spi_priv.h"
|
49 | 49 | #include"catalog/pg_index.h"
|
| 50 | +#include"catalog/pg_shadow.h" |
50 | 51 | #include"utils/relcache.h"
|
51 | 52 |
|
52 | 53 | #ifdef_DROP_COLUMN_HACK__
|
@@ -1449,6 +1450,70 @@ AlterTableDropConstraint(const char *relationName,
|
1449 | 1450 |
|
1450 | 1451 |
|
1451 | 1452 |
|
| 1453 | +/* |
| 1454 | + * ALTER TABLE OWNER |
| 1455 | + */ |
| 1456 | +void |
| 1457 | +AlterTableOwner(constchar*relationName,constchar*newOwnerName) |
| 1458 | +{ |
| 1459 | +Relationclass_rel; |
| 1460 | +HeapTupletuple; |
| 1461 | +int4newOwnerSysid; |
| 1462 | +Relationidescs[Num_pg_class_indices]; |
| 1463 | + |
| 1464 | +/* |
| 1465 | + * first check that we are a superuser |
| 1466 | + */ |
| 1467 | +if (!superuser() ) |
| 1468 | +elog(ERROR,"ALTER TABLE: permission denied"); |
| 1469 | + |
| 1470 | +/* |
| 1471 | + * look up the new owner in pg_shadow and get the sysid |
| 1472 | + */ |
| 1473 | +tuple=SearchSysCacheTuple(SHADOWNAME,PointerGetDatum(newOwnerName), |
| 1474 | +0,0,0); |
| 1475 | +if (!HeapTupleIsValid(tuple)) |
| 1476 | +elog(ERROR,"ALTER TABLE: user \"%s\" not found",newOwnerName); |
| 1477 | + |
| 1478 | +newOwnerSysid= ((Form_pg_shadow)GETSTRUCT(tuple))->usesysid; |
| 1479 | +heap_freetuple(tuple); |
| 1480 | + |
| 1481 | +/* |
| 1482 | + * find the table's entry in pg_class and lock it for writing |
| 1483 | + */ |
| 1484 | +class_rel=heap_openr(RelationRelationName,RowExclusiveLock); |
| 1485 | + |
| 1486 | +tuple=SearchSysCacheTuple(RELNAME,PointerGetDatum(relationName), |
| 1487 | +0,0,0); |
| 1488 | +if (!HeapTupleIsValid(tuple)) |
| 1489 | +elog(ERROR,"ALTER TABLE: relation \"%s\" not found", |
| 1490 | +relationName); |
| 1491 | + |
| 1492 | +if (((Form_pg_class)GETSTRUCT(tuple))->relkind!=RELKIND_RELATION) |
| 1493 | +elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table", |
| 1494 | +relationName); |
| 1495 | + |
| 1496 | +/* |
| 1497 | + * modify the table's entry and write to the heap |
| 1498 | + */ |
| 1499 | +((Form_pg_class)GETSTRUCT(tuple))->relowner=newOwnerSysid; |
| 1500 | + |
| 1501 | +heap_update(class_rel,&tuple->t_self,tuple,NULL); |
| 1502 | + |
| 1503 | +/* Keep the catalog indices up to date */ |
| 1504 | +CatalogOpenIndices(Num_pg_class_indices,Name_pg_class_indices,idescs); |
| 1505 | +CatalogIndexInsert(idescs,Num_pg_class_indices,class_rel,tuple); |
| 1506 | +CatalogCloseIndices(Num_pg_class_indices,idescs); |
| 1507 | + |
| 1508 | +/* |
| 1509 | + * unlock everything and return |
| 1510 | + */ |
| 1511 | +heap_freetuple(tuple); |
| 1512 | +heap_close(class_rel,RowExclusiveLock); |
| 1513 | + |
| 1514 | +return; |
| 1515 | +} |
| 1516 | + |
1452 | 1517 | /*
|
1453 | 1518 | * ALTER TABLE CREATE TOAST TABLE
|
1454 | 1519 | */
|
|