Skip to content

Commit f7ed465

Browse files
committed
Allow record_in() and record_recv() to work for transient record types.
If we have the typmod that identifies a registered record type, there's no reason that record_in() should refuse to perform input conversion for it. Now, in direct SQL usage, record_in() will always be passed typmod = -1 with type OID RECORDOID, because no typmodin exists for type RECORD, so the case can't arise. However, some InputFunctionCall users such as PLs may be able to supply the right typmod, so we should allow this to support them. Note: the previous coding and comment here predate commit 59c016a. There has been no case since 8.1 in which the passed type OID wouldn't be valid; and if it weren't, this error message wouldn't be apropos anyway. Better to let lookup_rowtype_tupdesc complain about it. Back-patch to 9.1, as this is necessary for my upcoming plpython fix. I'm committing it separately just to make it a bit more visible in the commit history.
1 parent 928d022 commit f7ed465

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/backend/utils/adt/rowtypes.c

+17-22
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,8 @@ record_in(PG_FUNCTION_ARGS)
7373
{
7474
char *string = PG_GETARG_CSTRING(0);
7575
Oid tupType = PG_GETARG_OID(1);
76-
77-
#ifdef NOT_USED
78-
int32 typmod = PG_GETARG_INT32(2);
79-
#endif
76+
int32 tupTypmod = PG_GETARG_INT32(2);
8077
HeapTupleHeader result;
81-
int32 tupTypmod;
8278
TupleDesc tupdesc;
8379
HeapTuple tuple;
8480
RecordIOData *my_extra;
@@ -91,16 +87,17 @@ record_in(PG_FUNCTION_ARGS)
9187
StringInfoData buf;
9288

9389
/*
94-
* Use the passed type unless it's RECORD; we can't support input of
95-
* anonymous types, mainly because there's no good way to figure out which
96-
* anonymous type is wanted. Note that for RECORD, what we'll probably
97-
* actually get is RECORD's typelem, ie, zero.
90+
* Give a friendly error message if we did not get enough info to identify
91+
* the target record type. (lookup_rowtype_tupdesc would fail anyway, but
92+
* with a non-user-friendly message.) In ordinary SQL usage, we'll get -1
93+
* for typmod, since composite types and RECORD have no type modifiers at
94+
* the SQL level, and thus must fail for RECORD. However some callers can
95+
* supply a valid typmod, and then we can do something useful for RECORD.
9896
*/
99-
if (tupType == InvalidOid || tupType == RECORDOID)
97+
if (tupType == RECORDOID && tupTypmod < 0)
10098
ereport(ERROR,
10199
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
102100
errmsg("input of anonymous composite types is not implemented")));
103-
tupTypmod = -1; /* for all non-anonymous types */
104101

105102
/*
106103
* This comes from the composite type's pg_type.oid and stores system oids
@@ -449,12 +446,8 @@ record_recv(PG_FUNCTION_ARGS)
449446
{
450447
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
451448
Oid tupType = PG_GETARG_OID(1);
452-
453-
#ifdef NOT_USED
454-
int32 typmod = PG_GETARG_INT32(2);
455-
#endif
449+
int32 tupTypmod = PG_GETARG_INT32(2);
456450
HeapTupleHeader result;
457-
int32 tupTypmod;
458451
TupleDesc tupdesc;
459452
HeapTuple tuple;
460453
RecordIOData *my_extra;
@@ -466,16 +459,18 @@ record_recv(PG_FUNCTION_ARGS)
466459
bool *nulls;
467460

468461
/*
469-
* Use the passed type unless it's RECORD; we can't support input of
470-
* anonymous types, mainly because there's no good way to figure out which
471-
* anonymous type is wanted. Note that for RECORD, what we'll probably
472-
* actually get is RECORD's typelem, ie, zero.
462+
* Give a friendly error message if we did not get enough info to identify
463+
* the target record type. (lookup_rowtype_tupdesc would fail anyway, but
464+
* with a non-user-friendly message.) In ordinary SQL usage, we'll get -1
465+
* for typmod, since composite types and RECORD have no type modifiers at
466+
* the SQL level, and thus must fail for RECORD. However some callers can
467+
* supply a valid typmod, and then we can do something useful for RECORD.
473468
*/
474-
if (tupType == InvalidOid || tupType == RECORDOID)
469+
if (tupType == RECORDOID && tupTypmod < 0)
475470
ereport(ERROR,
476471
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
477472
errmsg("input of anonymous composite types is not implemented")));
478-
tupTypmod = -1; /* for all non-anonymous types */
473+
479474
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
480475
ncolumns = tupdesc->natts;
481476

0 commit comments

Comments
 (0)