From 31effd10feb9d402f171a82b8d953a7441c0d082 Mon Sep 17 00:00:00 2001 From: Bruce Momjian <bruce@momjian.us> Date: Thu, 14 Mar 2002 22:44:50 +0000 Subject: [PATCH] The attached patch changes ALTER TABLE OWNER to also change the ownership of any toast tables that belong to the table that is being operated upon (as suggested by Tom Lane). Neil Conway --- src/backend/commands/command.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index b166ed539cd..c32be8b02f3 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.160 2002/03/06 19:58:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.161 2002/03/14 22:44:50 momjian Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -1619,11 +1619,13 @@ AlterTableOwnerId(Oid relationOid, int32 newOwnerSysId) CatalogCloseIndices(Num_pg_class_indices, idescs); /* - * If we are operating on a table, also change the ownership - * of all of its indexes. + * If we are operating on a table, also change the ownership of any + * indexes that belong to the table, as well as the table's toast + * table (if it has one) */ if (tuple_class->relkind == RELKIND_RELATION) { + /* Search for indexes belonging to this table */ Relation target_rel; List *index_oid_list, *i; @@ -1639,6 +1641,12 @@ AlterTableOwnerId(Oid relationOid, int32 newOwnerSysId) } freeList(index_oid_list); + + /* If it has a toast table, recurse to change its ownership */ + if (tuple_class->reltoastrelid != InvalidOid) + { + AlterTableOwnerId(tuple_class->reltoastrelid, newOwnerSysId); + } } heap_freetuple(tuple); @@ -1654,10 +1662,11 @@ CheckTupleType(Form_pg_class tuple_class) case RELKIND_INDEX: case RELKIND_VIEW: case RELKIND_SEQUENCE: + case RELKIND_TOASTVALUE: /* ok to change owner */ break; default: - elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table, index, view, or sequence", + elog(ERROR, "ALTER TABLE: relation \"%s\" is not a table, TOAST table, index, view, or sequence", NameStr(tuple_class->relname)); } } -- GitLab