changeDependencyFor() returns the number of pg_depend entries changed,
or 0 if there is a problem. The callers of this routine expect only one
dependency to change, but they did not check for the result returned.
The following code paths gain checks:
- Namespace for extensions.
- Namespace for various object types (see AlterObjectNamespace).
- Planner support function for a function.
Some existing error messages related to all that are reworded to be more
consistent with the project style, and the new error messages added
follow the same style. This change has exposed one bug fixed a bit
earlier with
bd5ddbe.
Reviewed-by: Heikki Linnakangas, Akshat Jaimini
Discussion: https://postgr.es/m/ZJzD/rn+UbloKjB7@paquier.xyz
pfree(nulls);
pfree(replaces);
- /* update dependencies to point to the new schema */
- changeDependencyFor(classId, objid,
- NamespaceRelationId, oldNspOid, nspOid);
+ /* update dependency to point to the new schema */
+ if (changeDependencyFor(classId, objid,
+ NamespaceRelationId, oldNspOid, nspOid) != 1)
+ elog(ERROR, "could not change schema dependency for object %u",
+ objid);
InvokeObjectPostAlterHook(classId, objid, 0);
AccessMethodRelationId,
relam1,
relam2) != 1)
- elog(ERROR, "failed to change access method dependency for relation \"%s.%s\"",
+ elog(ERROR, "could not change access method dependency for relation \"%s.%s\"",
get_namespace_name(get_rel_namespace(r1)),
get_rel_name(r1));
if (changeDependencyFor(RelationRelationId,
AccessMethodRelationId,
relam2,
relam1) != 1)
- elog(ERROR, "failed to change access method dependency for relation \"%s.%s\"",
+ elog(ERROR, "could not change access method dependency for relation \"%s.%s\"",
get_namespace_name(get_rel_namespace(r2)),
get_rel_name(r2));
}
table_close(extRel, RowExclusiveLock);
- /* update dependencies to point to the new schema */
- changeDependencyFor(ExtensionRelationId, extensionOid,
- NamespaceRelationId, oldNspOid, nspOid);
+ /* update dependency to point to the new schema */
+ if (changeDependencyFor(ExtensionRelationId, extensionOid,
+ NamespaceRelationId, oldNspOid, nspOid) != 1)
+ elog(ERROR, "could not change schema dependency for extension %s",
+ NameStr(extForm->extname));
InvokeObjectPostAlterHook(ExtensionRelationId, extensionOid, 0);
/* Add or replace dependency on support function */
if (OidIsValid(procForm->prosupport))
- changeDependencyFor(ProcedureRelationId, funcOid,
- ProcedureRelationId, procForm->prosupport,
- newsupport);
+ {
+ if (changeDependencyFor(ProcedureRelationId, funcOid,
+ ProcedureRelationId, procForm->prosupport,
+ newsupport) != 1)
+ elog(ERROR, "could not change support dependency for function %s",
+ get_func_name(funcOid));
+ }
else
{
ObjectAddress referenced;
NamespaceRelationId,
oldNspOid,
newNspOid) != 1)
- elog(ERROR, "failed to change schema dependency for relation \"%s\"",
+ elog(ERROR, "could not change schema dependency for relation \"%s\"",
NameStr(classForm->relname));
}
if (!already_done)
!isImplicitArray)
if (changeDependencyFor(TypeRelationId, typeOid,
NamespaceRelationId, oldNspOid, nspOid) != 1)
- elog(ERROR, "failed to change schema dependency for type %s",
+ elog(ERROR, "could not change schema dependency for type \"%s\"",
format_type_be(typeOid));
InvokeObjectPostAlterHook(TypeRelationId, typeOid, 0);