@@ -2029,8 +2029,8 @@ json_to_record(PG_FUNCTION_ARGS)
20292029static inline Datum
20302030populate_record_worker (FunctionCallInfo fcinfo , bool have_record_arg )
20312031{
2032- Oid argtype ;
2033- Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , have_record_arg ? 1 : 0 );
2032+ int json_arg_num = have_record_arg ? 1 : 0 ;
2033+ Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , json_arg_num );
20342034 text * json ;
20352035 Jsonb * jb = NULL ;
20362036 bool use_json_as_text ;
@@ -2049,12 +2049,12 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
20492049
20502050 Assert (jtype == JSONOID || jtype == JSONBOID );
20512051
2052- use_json_as_text = PG_ARGISNULL (have_record_arg ? 2 : 1 ) ? false :
2053- PG_GETARG_BOOL (have_record_arg ? 2 : 1 );
2052+ use_json_as_text = PG_ARGISNULL (json_arg_num + 1 ) ? false :
2053+ PG_GETARG_BOOL (json_arg_num + 1 );
20542054
20552055 if (have_record_arg )
20562056 {
2057- argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
2057+ Oid argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
20582058
20592059 if (!type_is_rowtype (argtype ))
20602060 ereport (ERROR ,
@@ -2091,8 +2091,6 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
20912091 else
20922092 { /* json{b}_to_record case */
20932093
2094- use_json_as_text = PG_ARGISNULL (1 ) ? false : PG_GETARG_BOOL (1 );
2095-
20962094 if (PG_ARGISNULL (0 ))
20972095 PG_RETURN_NULL ();
20982096
@@ -2108,7 +2106,7 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
21082106 if (jtype == JSONOID )
21092107 {
21102108 /* just get the text */
2111- json = PG_GETARG_TEXT_P (have_record_arg ? 1 : 0 );
2109+ json = PG_GETARG_TEXT_P (json_arg_num );
21122110
21132111 json_hash = get_json_object_as_hash (json , "json_populate_record" , use_json_as_text );
21142112
@@ -2123,7 +2121,7 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
21232121 }
21242122 else
21252123 {
2126- jb = PG_GETARG_JSONB (have_record_arg ? 1 : 0 );
2124+ jb = PG_GETARG_JSONB (json_arg_num );
21272125
21282126 /* same logic as for json */
21292127 if (!have_record_arg && rec )
@@ -2591,8 +2589,8 @@ json_to_recordset(PG_FUNCTION_ARGS)
25912589static inline Datum
25922590populate_recordset_worker (FunctionCallInfo fcinfo , bool have_record_arg )
25932591{
2594- Oid argtype ;
2595- Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , have_record_arg ? 1 : 0 );
2592+ int json_arg_num = have_record_arg ? 1 : 0 ;
2593+ Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , json_arg_num );
25962594 bool use_json_as_text ;
25972595 ReturnSetInfo * rsi ;
25982596 MemoryContext old_cxt ;
@@ -2604,22 +2602,16 @@ populate_recordset_worker(FunctionCallInfo fcinfo, bool have_record_arg)
26042602 int ncolumns ;
26052603 PopulateRecordsetState * state ;
26062604
2605+ use_json_as_text = PG_ARGISNULL (json_arg_num + 1 ) ? false : PG_GETARG_BOOL (json_arg_num + 1 );
2606+
26072607 if (have_record_arg )
26082608 {
2609- argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
2610-
2611- use_json_as_text = PG_ARGISNULL (2 ) ? false : PG_GETARG_BOOL (2 );
2609+ Oid argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
26122610
26132611 if (!type_is_rowtype (argtype ))
26142612 ereport (ERROR ,
26152613 (errcode (ERRCODE_DATATYPE_MISMATCH ),
2616- errmsg ("first argument of json_populate_recordset must be a row type" )));
2617- }
2618- else
2619- {
2620- argtype = InvalidOid ;
2621-
2622- use_json_as_text = PG_ARGISNULL (1 ) ? false : PG_GETARG_BOOL (1 );
2614+ errmsg ("first argument must be a row type" )));
26232615 }
26242616
26252617 rsi = (ReturnSetInfo * ) fcinfo -> resultinfo ;
@@ -2647,23 +2639,13 @@ populate_recordset_worker(FunctionCallInfo fcinfo, bool have_record_arg)
26472639 "that cannot accept type record" )));
26482640
26492641 /* if the json is null send back an empty set */
2650- if (have_record_arg )
2651- {
2652- if (PG_ARGISNULL (1 ))
2653- PG_RETURN_NULL ();
2654-
2655- if (PG_ARGISNULL (0 ))
2656- rec = NULL ;
2657- else
2658- rec = PG_GETARG_HEAPTUPLEHEADER (0 );
2659- }
2660- else
2661- {
2662- if (PG_ARGISNULL (1 ))
2663- PG_RETURN_NULL ();
2642+ if (PG_ARGISNULL (json_arg_num ))
2643+ PG_RETURN_NULL ();
26642644
2645+ if (!have_record_arg || PG_ARGISNULL (0 ))
26652646 rec = NULL ;
2666- }
2647+ else
2648+ rec = PG_GETARG_HEAPTUPLEHEADER (0 );
26672649
26682650 tupType = tupdesc -> tdtypeid ;
26692651 tupTypmod = tupdesc -> tdtypmod ;
0 commit comments