|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.232 2007/09/06 17:31:58 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.233 2007/09/29 17:18:58 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -5430,8 +5430,16 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing) |
5430 | 5430 | get_rel_name(tableId)))); |
5431 | 5431 | } |
5432 | 5432 | break; |
5433 | | -caseRELKIND_TOASTVALUE: |
5434 | 5433 | caseRELKIND_COMPOSITE_TYPE: |
| 5434 | +if (recursing) |
| 5435 | +break; |
| 5436 | +ereport(ERROR, |
| 5437 | +(errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 5438 | +errmsg("\"%s\" is a composite type", |
| 5439 | +NameStr(tuple_class->relname)), |
| 5440 | +errhint("Use ALTER TYPE instead."))); |
| 5441 | +break; |
| 5442 | +caseRELKIND_TOASTVALUE: |
5435 | 5443 | if (recursing) |
5436 | 5444 | break; |
5437 | 5445 | /* FALL THRU */ |
@@ -6478,31 +6486,48 @@ AlterTableNamespace(RangeVar *relation, const char *newschema) |
6478 | 6486 | OidnspOid; |
6479 | 6487 | RelationclassRel; |
6480 | 6488 |
|
6481 | | -rel=heap_openrv(relation,AccessExclusiveLock); |
| 6489 | +rel=relation_openrv(relation,AccessExclusiveLock); |
6482 | 6490 |
|
6483 | 6491 | relid=RelationGetRelid(rel); |
6484 | 6492 | oldNspOid=RelationGetNamespace(rel); |
6485 | 6493 |
|
6486 | | -/* heap_openrv allows TOAST, but we don't want to */ |
6487 | | -if (rel->rd_rel->relkind==RELKIND_TOASTVALUE) |
6488 | | -ereport(ERROR, |
6489 | | -(errcode(ERRCODE_WRONG_OBJECT_TYPE), |
6490 | | -errmsg("\"%s\" is a TOAST relation", |
6491 | | -RelationGetRelationName(rel)))); |
6492 | | - |
6493 | | -/* if it's an owned sequence, disallow moving it by itself */ |
6494 | | -if (rel->rd_rel->relkind==RELKIND_SEQUENCE) |
| 6494 | +/* Can we change the schema of this tuple? */ |
| 6495 | +switch (rel->rd_rel->relkind) |
6495 | 6496 | { |
6496 | | -OidtableId; |
6497 | | -int32colId; |
| 6497 | +caseRELKIND_RELATION: |
| 6498 | +caseRELKIND_VIEW: |
| 6499 | +/* ok to change schema */ |
| 6500 | +break; |
| 6501 | +caseRELKIND_SEQUENCE: |
| 6502 | +{ |
| 6503 | +/* if it's an owned sequence, disallow moving it by itself */ |
| 6504 | +OidtableId; |
| 6505 | +int32colId; |
6498 | 6506 |
|
6499 | | -if (sequenceIsOwned(relid,&tableId,&colId)) |
| 6507 | +if (sequenceIsOwned(relid,&tableId,&colId)) |
| 6508 | +ereport(ERROR, |
| 6509 | +(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 6510 | +errmsg("cannot move an owned sequence into another schema"), |
| 6511 | +errdetail("Sequence \"%s\" is linked to table \"%s\".", |
| 6512 | +RelationGetRelationName(rel), |
| 6513 | +get_rel_name(tableId)))); |
| 6514 | +} |
| 6515 | +break; |
| 6516 | +caseRELKIND_COMPOSITE_TYPE: |
6500 | 6517 | ereport(ERROR, |
6501 | | -(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
6502 | | -errmsg("cannot move an owned sequence into another schema"), |
6503 | | -errdetail("Sequence \"%s\" is linked to table \"%s\".", |
6504 | | -RelationGetRelationName(rel), |
6505 | | -get_rel_name(tableId)))); |
| 6518 | +(errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 6519 | +errmsg("\"%s\" is a composite type", |
| 6520 | +RelationGetRelationName(rel)), |
| 6521 | +errhint("Use ALTER TYPE instead."))); |
| 6522 | +break; |
| 6523 | +caseRELKIND_INDEX: |
| 6524 | +caseRELKIND_TOASTVALUE: |
| 6525 | +/* FALL THRU */ |
| 6526 | +default: |
| 6527 | +ereport(ERROR, |
| 6528 | +(errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 6529 | +errmsg("\"%s\" is not a table, view, or sequence", |
| 6530 | +RelationGetRelationName(rel)))); |
6506 | 6531 | } |
6507 | 6532 |
|
6508 | 6533 | /* get schema OID and check its permissions */ |
|