Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20bef3f

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 noreason that record_in() should refuse to perform input conversion for it.Now, in direct SQL usage, record_in() will always be passed typmod = -1with type OID RECORDOID, because no typmodin exists for type RECORD, so thecase can't arise. However, some InputFunctionCall users such as PLs may beable to supply the right typmod, so we should allow this to support them.Note: the previous coding and comment here predate commit59c016a.There has been no case since 8.1 in which the passed type OID wouldn't bevalid; 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 thecommit history.
1 parent49f9a28 commit20bef3f

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

‎src/backend/utils/adt/rowtypes.c

Lines changed: 17 additions & 22 deletions
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
OidtupType=PG_GETARG_OID(1);
76-
77-
#ifdefNOT_USED
78-
int32typmod=PG_GETARG_INT32(2);
79-
#endif
76+
int32tupTypmod=PG_GETARG_INT32(2);
8077
HeapTupleHeaderresult;
81-
int32tupTypmod;
8278
TupleDesctupdesc;
8379
HeapTupletuple;
8480
RecordIOData*my_extra;
@@ -91,16 +87,17 @@ record_in(PG_FUNCTION_ARGS)
9187
StringInfoDatabuf;
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
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
451448
OidtupType=PG_GETARG_OID(1);
452-
453-
#ifdefNOT_USED
454-
int32typmod=PG_GETARG_INT32(2);
455-
#endif
449+
int32tupTypmod=PG_GETARG_INT32(2);
456450
HeapTupleHeaderresult;
457-
int32tupTypmod;
458451
TupleDesctupdesc;
459452
HeapTupletuple;
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)

[8]ページ先頭

©2009-2025 Movatter.jp