From 30681c830d69ca88cf66105c94e63d3e4d905681 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 16 Jun 2017 11:33:12 +0300 Subject: Fix dependency, when changing a function's argument/return type. When a new base type is created using the old-style procedure of first creating the input/output functions with "opaque" in place of the base type, the "opaque" argument/return type is changed to the final base type, on CREATE TYPE. However, we did not create a pg_depend record when doing that, so the functions were left not depending on the type. Fixes bug #14706, reported by Karen Huddleston. Discussion: https://www.postgresql.org/message-id/20170614232259.1424.82774@wrigleys.postgresql.org --- src/backend/commands/functioncmds.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/backend/commands/functioncmds.c') diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index ffcae341892..02c740c13a6 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1316,6 +1316,8 @@ SetFunctionReturnType(Oid funcOid, Oid newRetType) Relation pg_proc_rel; HeapTuple tup; Form_pg_proc procForm; + ObjectAddress func_address; + ObjectAddress type_address; pg_proc_rel = heap_open(ProcedureRelationId, RowExclusiveLock); @@ -1334,6 +1336,14 @@ SetFunctionReturnType(Oid funcOid, Oid newRetType) CatalogTupleUpdate(pg_proc_rel, &tup->t_self, tup); heap_close(pg_proc_rel, RowExclusiveLock); + + /* + * Also update the dependency to the new type. Opaque is a pinned type, so + * there is no old dependency record for it that we would need to remove. + */ + ObjectAddressSet(type_address, TypeRelationId, newRetType); + ObjectAddressSet(func_address, ProcedureRelationId, funcOid); + recordDependencyOn(&func_address, &type_address, DEPENDENCY_NORMAL); } @@ -1348,6 +1358,8 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType) Relation pg_proc_rel; HeapTuple tup; Form_pg_proc procForm; + ObjectAddress func_address; + ObjectAddress type_address; pg_proc_rel = heap_open(ProcedureRelationId, RowExclusiveLock); @@ -1367,6 +1379,14 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType) CatalogTupleUpdate(pg_proc_rel, &tup->t_self, tup); heap_close(pg_proc_rel, RowExclusiveLock); + + /* + * Also update the dependency to the new type. Opaque is a pinned type, so + * there is no old dependency record for it that we would need to remove. + */ + ObjectAddressSet(type_address, TypeRelationId, newArgType); + ObjectAddressSet(func_address, ProcedureRelationId, funcOid); + recordDependencyOn(&func_address, &type_address, DEPENDENCY_NORMAL); } -- cgit v1.2.3