aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2017-06-16 11:33:12 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2017-06-16 11:33:12 +0300
commit30681c830d69ca88cf66105c94e63d3e4d905681 (patch)
tree6b2c2c900930ec7da43f926e691a1e0937de354f /src
parent39ac55918fc31b9bf88185d28ebe7ddc58d01181 (diff)
downloadpostgresql-30681c830d69ca88cf66105c94e63d3e4d905681.tar.gz
postgresql-30681c830d69ca88cf66105c94e63d3e4d905681.zip
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')
-rw-r--r--src/backend/commands/functioncmds.c20
-rw-r--r--src/test/regress/expected/create_type.out25
-rw-r--r--src/test/regress/sql/create_type.sql11
3 files changed, 56 insertions, 0 deletions
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);
}
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 7bdad4e9bb5..5886a1f37f3 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -115,6 +115,31 @@ CREATE TYPE not_existing_type (INPUT = array_in,
ELEMENT = int,
INTERNALLENGTH = 32);
ERROR: function array_out(not_existing_type) does not exist
+-- Check dependency transfer of opaque functions when creating a new type
+CREATE FUNCTION base_fn_in(cstring) RETURNS opaque AS 'boolin'
+ LANGUAGE internal IMMUTABLE STRICT;
+CREATE FUNCTION base_fn_out(opaque) RETURNS opaque AS 'boolout'
+ LANGUAGE internal IMMUTABLE STRICT;
+CREATE TYPE base_type(INPUT = base_fn_in, OUTPUT = base_fn_out);
+WARNING: changing argument type of function base_fn_out from "opaque" to base_type
+WARNING: changing return type of function base_fn_in from opaque to base_type
+WARNING: changing return type of function base_fn_out from opaque to cstring
+DROP FUNCTION base_fn_in(cstring); -- error
+ERROR: cannot drop function base_fn_in(cstring) because other objects depend on it
+DETAIL: type base_type depends on function base_fn_in(cstring)
+function base_fn_out(base_type) depends on type base_type
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+DROP FUNCTION base_fn_out(opaque); -- error
+ERROR: function base_fn_out(opaque) does not exist
+DROP TYPE base_type; -- error
+ERROR: cannot drop type base_type because other objects depend on it
+DETAIL: function base_fn_out(base_type) depends on type base_type
+function base_fn_in(cstring) depends on type base_type
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+DROP TYPE base_type CASCADE;
+NOTICE: drop cascades to 2 other objects
+DETAIL: drop cascades to function base_fn_out(base_type)
+drop cascades to function base_fn_in(cstring)
-- Check usage of typmod with a user-defined type
-- (we have borrowed numeric's typmod functions)
CREATE TEMP TABLE mytab (foo widget(42,13,7)); -- should fail
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index a1839ef9e7f..a28303aa6a9 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -115,6 +115,17 @@ CREATE TYPE not_existing_type (INPUT = array_in,
ELEMENT = int,
INTERNALLENGTH = 32);
+-- Check dependency transfer of opaque functions when creating a new type
+CREATE FUNCTION base_fn_in(cstring) RETURNS opaque AS 'boolin'
+ LANGUAGE internal IMMUTABLE STRICT;
+CREATE FUNCTION base_fn_out(opaque) RETURNS opaque AS 'boolout'
+ LANGUAGE internal IMMUTABLE STRICT;
+CREATE TYPE base_type(INPUT = base_fn_in, OUTPUT = base_fn_out);
+DROP FUNCTION base_fn_in(cstring); -- error
+DROP FUNCTION base_fn_out(opaque); -- error
+DROP TYPE base_type; -- error
+DROP TYPE base_type CASCADE;
+
-- Check usage of typmod with a user-defined type
-- (we have borrowed numeric's typmod functions)