Skip to content

Commit 50a16e3

Browse files
committed
Use the right type OID after creating a shell type
Commit a2e35b5 neglected to update the type OID to use further down in DefineType when TypeShellMake was changed to return ObjectAddress instead of OID (it got it right in DefineRange, however.) This resulted in an internal error message being issued when looking up I/O functions. Author: Michael Paquier Also add Asserts() to a couple of other places to ensure that the type OID being used is as expected.
1 parent 450fa1b commit 50a16e3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/backend/commands/typecmds.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ DefineType(List *names, List *parameters)
215215
if (!OidIsValid(typoid))
216216
{
217217
address = TypeShellMake(typeName, typeNamespace, GetUserId());
218+
typoid = address.objectId;
218219
/* Make new shell type visible for modification below */
219220
CommandCounterIncrement();
220221

@@ -628,6 +629,7 @@ DefineType(List *names, List *parameters)
628629
0, /* Array Dimensions of typbasetype */
629630
false, /* Type NOT NULL */
630631
collation); /* type's collation */
632+
Assert(typoid == address.objectId);
631633

632634
/*
633635
* Create the array type that goes with it.
@@ -1505,7 +1507,7 @@ DefineRange(CreateRangeStmt *stmt)
15051507
0, /* Array dimensions of typbasetype */
15061508
false, /* Type NOT NULL */
15071509
InvalidOid); /* type's collation (ranges never have one) */
1508-
typoid = address.objectId;
1510+
Assert(typoid == address.objectId);
15091511

15101512
/* Create the entry in pg_range */
15111513
RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass,

src/test/regress/expected/create_type.out

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ ERROR: type "text_w_default" already exists
107107
DROP TYPE default_test_row CASCADE;
108108
NOTICE: drop cascades to function get_default_test()
109109
DROP TABLE default_test;
110+
-- Check type create with input/output incompatibility
111+
CREATE TYPE not_existing_type (INPUT = array_in,
112+
OUTPUT = array_out,
113+
ELEMENT = int,
114+
INTERNALLENGTH = 32);
115+
ERROR: function array_out(not_existing_type) does not exist
110116
-- Check usage of typmod with a user-defined type
111117
-- (we have borrowed numeric's typmod functions)
112118
CREATE TEMP TABLE mytab (foo widget(42,13,7)); -- should fail

src/test/regress/sql/create_type.sql

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ DROP TYPE default_test_row CASCADE;
106106

107107
DROP TABLE default_test;
108108

109+
-- Check type create with input/output incompatibility
110+
CREATE TYPE not_existing_type (INPUT = array_in,
111+
OUTPUT = array_out,
112+
ELEMENT = int,
113+
INTERNALLENGTH = 32);
114+
109115
-- Check usage of typmod with a user-defined type
110116
-- (we have borrowed numeric's typmod functions)
111117

0 commit comments

Comments
 (0)