@@ -85,8 +85,7 @@ static void elements_array_element_end(void *state, bool isnull);
85
85
static void elements_scalar (void * state , char * token , JsonTokenType tokentype );
86
86
87
87
/* turn a json object into a hash table */
88
- static HTAB * get_json_object_as_hash (text * json , const char * funcname ,
89
- bool use_json_as_text );
88
+ static HTAB * get_json_object_as_hash (text * json , const char * funcname );
90
89
91
90
/* common worker for populate_record and to_record */
92
91
static Datum populate_record_worker (FunctionCallInfo fcinfo , const char * funcname ,
@@ -198,7 +197,6 @@ typedef struct JhashState
198
197
HTAB * hash ;
199
198
char * saved_scalar ;
200
199
char * save_json_start ;
201
- bool use_json_as_text ;
202
200
} JHashState ;
203
201
204
202
/* hashtable element */
@@ -235,7 +233,6 @@ typedef struct PopulateRecordsetState
235
233
HTAB * json_hash ;
236
234
char * saved_scalar ;
237
235
char * save_json_start ;
238
- bool use_json_as_text ;
239
236
Tuplestorestate * tuple_store ;
240
237
TupleDesc ret_tdesc ;
241
238
HeapTupleHeader rec ;
@@ -1989,7 +1986,6 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
1989
1986
Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , json_arg_num );
1990
1987
text * json ;
1991
1988
Jsonb * jb = NULL ;
1992
- bool use_json_as_text ;
1993
1989
HTAB * json_hash = NULL ;
1994
1990
HeapTupleHeader rec = NULL ;
1995
1991
Oid tupType = InvalidOid ;
@@ -2005,9 +2001,6 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
2005
2001
2006
2002
Assert (jtype == JSONOID || jtype == JSONBOID );
2007
2003
2008
- use_json_as_text = PG_ARGISNULL (json_arg_num + 1 ) ? false :
2009
- PG_GETARG_BOOL (json_arg_num + 1 );
2010
-
2011
2004
if (have_record_arg )
2012
2005
{
2013
2006
Oid argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
@@ -2065,7 +2058,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
2065
2058
/* just get the text */
2066
2059
json = PG_GETARG_TEXT_P (json_arg_num );
2067
2060
2068
- json_hash = get_json_object_as_hash (json , funcname , use_json_as_text );
2061
+ json_hash = get_json_object_as_hash (json , funcname );
2069
2062
2070
2063
/*
2071
2064
* if the input json is empty, we can only skip the rest if we were
@@ -2227,10 +2220,6 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
2227
2220
else if (v -> type == jbvNumeric )
2228
2221
s = DatumGetCString (DirectFunctionCall1 (numeric_out ,
2229
2222
PointerGetDatum (v -> val .numeric )));
2230
- else if (!use_json_as_text )
2231
- ereport (ERROR ,
2232
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2233
- errmsg ("cannot populate with a nested object unless use_json_as_text is true" )));
2234
2223
else if (v -> type == jbvBinary )
2235
2224
s = JsonbToCString (NULL , (JsonbContainer * ) v -> val .binary .data , v -> val .binary .len );
2236
2225
else
@@ -2258,15 +2247,9 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
2258
2247
* get_json_object_as_hash
2259
2248
*
2260
2249
* decompose a json object into a hash table.
2261
- *
2262
- * Currently doesn't allow anything but a flat object. Should this
2263
- * change?
2264
- *
2265
- * funcname argument allows caller to pass in its name for use in
2266
- * error messages.
2267
2250
*/
2268
2251
static HTAB *
2269
- get_json_object_as_hash (text * json , const char * funcname , bool use_json_as_text )
2252
+ get_json_object_as_hash (text * json , const char * funcname )
2270
2253
{
2271
2254
HASHCTL ctl ;
2272
2255
HTAB * tab ;
@@ -2289,7 +2272,6 @@ get_json_object_as_hash(text *json, const char *funcname, bool use_json_as_text)
2289
2272
state -> function_name = funcname ;
2290
2273
state -> hash = tab ;
2291
2274
state -> lex = lex ;
2292
- state -> use_json_as_text = use_json_as_text ;
2293
2275
2294
2276
sem -> semstate = (void * ) state ;
2295
2277
sem -> array_start = hash_array_start ;
@@ -2313,11 +2295,7 @@ hash_object_field_start(void *state, char *fname, bool isnull)
2313
2295
if (_state -> lex -> token_type == JSON_TOKEN_ARRAY_START ||
2314
2296
_state -> lex -> token_type == JSON_TOKEN_OBJECT_START )
2315
2297
{
2316
- if (!_state -> use_json_as_text )
2317
- ereport (ERROR ,
2318
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2319
- errmsg ("cannot call %s on a nested object" ,
2320
- _state -> function_name )));
2298
+ /* remember start position of the whole text of the subobject */
2321
2299
_state -> save_json_start = _state -> lex -> token_start ;
2322
2300
}
2323
2301
else
@@ -2535,10 +2513,6 @@ make_row_from_rec_and_jsonb(Jsonb *element, PopulateRecordsetState *state)
2535
2513
else if (v -> type == jbvNumeric )
2536
2514
s = DatumGetCString (DirectFunctionCall1 (numeric_out ,
2537
2515
PointerGetDatum (v -> val .numeric )));
2538
- else if (!state -> use_json_as_text )
2539
- ereport (ERROR ,
2540
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2541
- errmsg ("cannot populate with a nested object unless use_json_as_text is true" )));
2542
2516
else if (v -> type == jbvBinary )
2543
2517
s = JsonbToCString (NULL , (JsonbContainer * ) v -> val .binary .data , v -> val .binary .len );
2544
2518
else
@@ -2565,7 +2539,6 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
2565
2539
{
2566
2540
int json_arg_num = have_record_arg ? 1 : 0 ;
2567
2541
Oid jtype = get_fn_expr_argtype (fcinfo -> flinfo , json_arg_num );
2568
- bool use_json_as_text ;
2569
2542
ReturnSetInfo * rsi ;
2570
2543
MemoryContext old_cxt ;
2571
2544
Oid tupType ;
@@ -2576,8 +2549,6 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
2576
2549
int ncolumns ;
2577
2550
PopulateRecordsetState * state ;
2578
2551
2579
- use_json_as_text = PG_ARGISNULL (json_arg_num + 1 ) ? false : PG_GETARG_BOOL (json_arg_num + 1 );
2580
-
2581
2552
if (have_record_arg )
2582
2553
{
2583
2554
Oid argtype = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
@@ -2667,7 +2638,6 @@ populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
2667
2638
state -> function_name = funcname ;
2668
2639
state -> my_extra = my_extra ;
2669
2640
state -> rec = rec ;
2670
- state -> use_json_as_text = use_json_as_text ;
2671
2641
state -> fn_mcxt = fcinfo -> flinfo -> fn_mcxt ;
2672
2642
2673
2643
if (jtype == JSONOID )
@@ -2749,16 +2719,9 @@ populate_recordset_object_start(void *state)
2749
2719
errmsg ("cannot call %s on an object" ,
2750
2720
_state -> function_name )));
2751
2721
2752
- /* Nested objects, if allowed, require no special processing */
2722
+ /* Nested objects require no special processing */
2753
2723
if (lex_level > 1 )
2754
- {
2755
- if (!_state -> use_json_as_text )
2756
- ereport (ERROR ,
2757
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2758
- errmsg ("cannot call %s with nested objects" ,
2759
- _state -> function_name )));
2760
2724
return ;
2761
- }
2762
2725
2763
2726
/* Object at level 1: set up a new hash table for this object */
2764
2727
memset (& ctl , 0 , sizeof (ctl ));
@@ -2903,13 +2866,7 @@ populate_recordset_array_element_start(void *state, bool isnull)
2903
2866
static void
2904
2867
populate_recordset_array_start (void * state )
2905
2868
{
2906
- PopulateRecordsetState * _state = (PopulateRecordsetState * ) state ;
2907
-
2908
- if (_state -> lex -> lex_level != 0 && !_state -> use_json_as_text )
2909
- ereport (ERROR ,
2910
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2911
- errmsg ("cannot call %s with nested arrays" ,
2912
- _state -> function_name )));
2869
+ /* nothing to do */
2913
2870
}
2914
2871
2915
2872
static void
@@ -2938,11 +2895,6 @@ populate_recordset_object_field_start(void *state, char *fname, bool isnull)
2938
2895
if (_state -> lex -> token_type == JSON_TOKEN_ARRAY_START ||
2939
2896
_state -> lex -> token_type == JSON_TOKEN_OBJECT_START )
2940
2897
{
2941
- if (!_state -> use_json_as_text )
2942
- ereport (ERROR ,
2943
- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
2944
- errmsg ("cannot call %s on a nested object" ,
2945
- _state -> function_name )));
2946
2898
_state -> save_json_start = _state -> lex -> token_start ;
2947
2899
}
2948
2900
else
0 commit comments