@@ -116,6 +116,7 @@ typedef struct SQLFunctionHashEntry
116
116
char * src ; /* function body text (for error msgs) */
117
117
118
118
SQLFunctionParseInfoPtr pinfo ; /* data for parser callback hooks */
119
+ int16 * argtyplen ; /* lengths of the input argument types */
119
120
120
121
Oid rettype ; /* actual return type */
121
122
int16 typlen ; /* length of the return type */
@@ -1100,6 +1101,15 @@ sql_compile_callback(FunctionCallInfo fcinfo,
1100
1101
PG_GET_COLLATION ());
1101
1102
MemoryContextSwitchTo (oldcontext );
1102
1103
1104
+ /*
1105
+ * Now that we have the resolved argument types, collect their typlens for
1106
+ * use in postquel_sub_params.
1107
+ */
1108
+ func -> argtyplen = (int16 * )
1109
+ MemoryContextAlloc (hcontext , func -> pinfo -> nargs * sizeof (int16 ));
1110
+ for (int i = 0 ; i < func -> pinfo -> nargs ; i ++ )
1111
+ func -> argtyplen [i ] = get_typlen (func -> pinfo -> argtypes [i ]);
1112
+
1103
1113
/*
1104
1114
* And of course we need the function body text.
1105
1115
*/
@@ -1427,6 +1437,7 @@ postquel_sub_params(SQLFunctionCachePtr fcache,
1427
1437
{
1428
1438
ParamListInfo paramLI ;
1429
1439
Oid * argtypes = fcache -> func -> pinfo -> argtypes ;
1440
+ int16 * argtyplen = fcache -> func -> argtyplen ;
1430
1441
1431
1442
if (fcache -> paramLI == NULL )
1432
1443
{
@@ -1463,7 +1474,7 @@ postquel_sub_params(SQLFunctionCachePtr fcache,
1463
1474
prm -> isnull = fcinfo -> args [i ].isnull ;
1464
1475
prm -> value = MakeExpandedObjectReadOnly (fcinfo -> args [i ].value ,
1465
1476
prm -> isnull ,
1466
- get_typlen ( argtypes [i ]) );
1477
+ argtyplen [i ]);
1467
1478
/* Allow the value to be substituted into custom plans */
1468
1479
prm -> pflags = PARAM_FLAG_CONST ;
1469
1480
prm -> ptype = argtypes [i ];
0 commit comments