diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2017-06-15 10:42:10 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2017-06-16 11:46:11 +0300 |
commit | b47e2f7a94631c9dc8374339de2f668d898cd1c6 (patch) | |
tree | 7a88dd9af6b02d45c63058e9c141a1d45ee859d7 /src/backend/commands/functioncmds.c | |
parent | 99090e977d51107b25ba1670801975d6d1495d74 (diff) |
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
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r-- | src/backend/commands/functioncmds.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 53c4ab359d9..93d1065198b 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1189,6 +1189,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); @@ -1209,6 +1211,20 @@ SetFunctionReturnType(Oid funcOid, Oid newRetType) CatalogUpdateIndexes(pg_proc_rel, 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. + */ + type_address.classId = TypeRelationId; + type_address.objectId = newRetType; + type_address.objectSubId = 0; + + func_address.classId = ProcedureRelationId; + func_address.objectId = funcOid; + func_address.objectSubId = 0; + + recordDependencyOn(&func_address, &type_address, DEPENDENCY_NORMAL); } @@ -1223,6 +1239,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); @@ -1244,6 +1262,20 @@ SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType) CatalogUpdateIndexes(pg_proc_rel, 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. + */ + type_address.classId = TypeRelationId; + type_address.objectId = newArgType; + type_address.objectSubId = 0; + + func_address.classId = ProcedureRelationId; + func_address.objectId = funcOid; + func_address.objectSubId = 0; + + recordDependencyOn(&func_address, &type_address, DEPENDENCY_NORMAL); } |