Here is an updated version of your patch. Would you supply SGML
documentation updates to match the code changes? Thanks.
---
Bernd Helmle wrote:
Here's my current patch for ALTER OBJECT SET SCHEMA: the attached patch
file implements
schema move for FUNCTION, SEQUENCE, TYPE, DOMAIN and TABLE with all
improvements discussed on -hackers recently. Altering OPERATOR, OPERATOR
CLASS, AGGREGATE and CONVERSION are currently not implemented (since i ran
out of time) :(
Supported syntax is
ALTER TABLE name SET SCHEMA name;
ALTER SEQUENCE name SET SCHEMA name;
ALTER FUNCTION name SET SCHEMA name;
ALTER TYPE name SET SCHEMA name;
ALTER DOMAIN name SET SCHEMA name;
TIA
--
Bernd
[ Attachment, skipping... ]
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
--
Bruce Momjian| http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup.| Newtown Square, Pennsylvania 19073
Index: src/backend/catalog/pg_depend.c
===
RCS file: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v
retrieving revision 1.13
diff -c -c -r1.13 pg_depend.c
*** src/backend/catalog/pg_depend.c 14 Apr 2005 20:03:23 - 1.13
--- src/backend/catalog/pg_depend.c 29 Jul 2005 03:11:17 -
***
*** 211,213
--- 211,273
return ret;
}
+
+ bool
+ changeDependencyFor(Oid classId, Oid objectId, Oid oldrefobjectId,
+ Oid newrefobjectId)
+ {
+ ScanKeyData key[2];
+ SysScanDesc scan;
+ HeapTuple tup;
+ RelationdepRel;
+ boolresult = false; /* nothing changed */
+
+ Assert(OidIsValid(classId) OidIsValid(objectId)
+ OidIsValid(oldrefobjectId) OidIsValid(newrefobjectId));
+
+ depRel = heap_open(DependRelationId, RowExclusiveLock);
+
+ ScanKeyInit(key[0], Anum_pg_depend_classid, BTEqualStrategyNumber,
F_OIDEQ,
+ ObjectIdGetDatum(classId));
+ ScanKeyInit(key[1], Anum_pg_depend_objid, BTEqualStrategyNumber,
F_OIDEQ,
+ ObjectIdGetDatum(objectId));
+
+ scan = systable_beginscan(depRel, DependDependerIndexId, true,
+ SnapshotNow, 2, key);
+
+ while (HeapTupleIsValid((tup = systable_getnext(scan
+ {
+ Form_pg_depend depend_class = (Form_pg_depend) GETSTRUCT(tup);
+
+ if (depend_class-refobjid == oldrefobjectId)
+ {
+ ObjectAddress objAddr;
+
+ objAddr.classId = classId;
+ objAddr.objectId = oldrefobjectId;
+ objAddr.objectSubId = 0;
+
+ if (isObjectPinned(objAddr, depRel))
+ elog(ERROR, attempt to change dependency on a
system object!);
+
+ tup = heap_copytuple(tup);
+ depend_class = (Form_pg_depend) GETSTRUCT(tup);
+
+ depend_class-refobjid = newrefobjectId;
+ simple_heap_update(depRel, tup-t_self, tup);
+ CatalogUpdateIndexes(depRel, tup);
+
+ /*
+* Assume that the specified object/classId couldn't
reference the
+* changed object twice, so exit the loop immediately.
+*/
+ result = true;
+ break;
+ }
+ }
+
+ systable_endscan(scan);
+ heap_close(depRel, RowExclusiveLock);
+
+ return result;
+ }
Index: src/backend/commands/alter.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/alter.c,v
retrieving revision 1.13
diff -c -c -r1.13 alter.c
*** src/backend/commands/alter.c28 Jun 2005 05:08:53 - 1.13
--- src/backend/commands/alter.c29 Jul 2005 03:11:17 -
***
*** 38,43
--- 38,75
/*
+ * Executes an ALTER OBJECT / SET SCHEMA statement
+ */
+ void
+ ExecRenameObjSchemaStmt(RenameObjSchemaStmt *stmt)
+ {
+ Oid relid;
+
+ switch (stmt-renameType)
+ {
+ case OBJECT_TYPE:
+ case OBJECT_DOMAIN:
+ AlterDomainNamespace(stmt-object, stmt-newname);
+ break;
+
+ case OBJECT_FUNCTION:
+ AlterFunctionNamespace(stmt-object, stmt-objarg,