@@ -2029,8 +2029,8 @@ json_to_record(PG_FUNCTION_ARGS)
2029
2029
static inline Datum
2030
2030
populate_record_worker (FunctionCallInfo fcinfo , bool have_record_arg )
2031
2031
{
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 );
2034
2034
text * json ;
2035
2035
Jsonb * jb = NULL ;
2036
2036
bool use_json_as_text ;
@@ -2049,12 +2049,12 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2049
2049
2050
2050
Assert (jtype == JSONOID || jtype == JSONBOID );
2051
2051
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 );
2054
2054
2055
2055
if (have_record_arg )
2056
2056
{
2057
- argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
2057
+ Oid argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
2058
2058
2059
2059
if (!type_is_rowtype (argtype ))
2060
2060
ereport (ERROR ,
@@ -2091,8 +2091,6 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2091
2091
else
2092
2092
{ /* json{b}_to_record case */
2093
2093
2094
- use_json_as_text = PG_ARGISNULL (1 ) ? false : PG_GETARG_BOOL (1 );
2095
-
2096
2094
if (PG_ARGISNULL (0 ))
2097
2095
PG_RETURN_NULL ();
2098
2096
@@ -2108,7 +2106,7 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2108
2106
if (jtype == JSONOID )
2109
2107
{
2110
2108
/* just get the text */
2111
- json = PG_GETARG_TEXT_P (have_record_arg ? 1 : 0 );
2109
+ json = PG_GETARG_TEXT_P (json_arg_num );
2112
2110
2113
2111
json_hash = get_json_object_as_hash (json , "json_populate_record" , use_json_as_text );
2114
2112
@@ -2123,7 +2121,7 @@ populate_record_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2123
2121
}
2124
2122
else
2125
2123
{
2126
- jb = PG_GETARG_JSONB (have_record_arg ? 1 : 0 );
2124
+ jb = PG_GETARG_JSONB (json_arg_num );
2127
2125
2128
2126
/* same logic as for json */
2129
2127
if (!have_record_arg && rec )
@@ -2591,8 +2589,8 @@ json_to_recordset(PG_FUNCTION_ARGS)
2591
2589
static inline Datum
2592
2590
populate_recordset_worker (FunctionCallInfo fcinfo , bool have_record_arg )
2593
2591
{
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 );
2596
2594
bool use_json_as_text ;
2597
2595
ReturnSetInfo * rsi ;
2598
2596
MemoryContext old_cxt ;
@@ -2604,22 +2602,16 @@ populate_recordset_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2604
2602
int ncolumns ;
2605
2603
PopulateRecordsetState * state ;
2606
2604
2605
+ use_json_as_text = PG_ARGISNULL (json_arg_num + 1 ) ? false : PG_GETARG_BOOL (json_arg_num + 1 );
2606
+
2607
2607
if (have_record_arg )
2608
2608
{
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 );
2612
2610
2613
2611
if (!type_is_rowtype (argtype ))
2614
2612
ereport (ERROR ,
2615
2613
(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" )));
2623
2615
}
2624
2616
2625
2617
rsi = (ReturnSetInfo * ) fcinfo -> resultinfo ;
@@ -2647,23 +2639,13 @@ populate_recordset_worker(FunctionCallInfo fcinfo, bool have_record_arg)
2647
2639
"that cannot accept type record" )));
2648
2640
2649
2641
/* 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 ();
2664
2644
2645
+ if (!have_record_arg || PG_ARGISNULL (0 ))
2665
2646
rec = NULL ;
2666
- }
2647
+ else
2648
+ rec = PG_GETARG_HEAPTUPLEHEADER (0 );
2667
2649
2668
2650
tupType = tupdesc -> tdtypeid ;
2669
2651
tupTypmod = tupdesc -> tdtypmod ;
0 commit comments