@ -61,11 +61,11 @@ typedef enum /* type categories for datum_to_jsonb */
typedef struct JsonbAggState
{
JsonbInState * res ;
JsonbTypeCategory key_category ;
Oid key_output_func ;
JsonbTypeCategory val_category ;
Oid val_output_func ;
JsonbInState * res ;
JsonbTypeCategory key_category ;
Oid key_output_func ;
JsonbTypeCategory val_category ;
Oid val_output_func ;
} JsonbAggState ;
static inline Datum jsonb_from_cstring ( char * json , int len ) ;
@ -714,6 +714,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
check_stack_depth ( ) ;
/* Convert val to a JsonbValue in jb (in most cases) */
if ( is_null )
{
Assert ( ! key_scalar ) ;
@ -936,8 +937,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
break ;
}
}
if ( tcategory > = JSONBTYPE_JSON & & tcategory < = JSONBTYPE_JSONCAST & &
! scalar_jsonb )
/* Now insert jb into result, unless we did it recursively */
if ( ! is_null & & ! scalar_jsonb & &
tcategory > = JSONBTYPE_JSON & & tcategory < = JSONBTYPE_JSONCAST )
{
/* work has been done recursively */
return ;
@ -1607,8 +1610,7 @@ jsonb_agg_transfn(PG_FUNCTION_ARGS)
if ( PG_ARGISNULL ( 0 ) )
{
Oid arg_type = get_fn_expr_argtype ( fcinfo - > flinfo , 1 ) ;
Oid arg_type = get_fn_expr_argtype ( fcinfo - > flinfo , 1 ) ;
if ( arg_type = = InvalidOid )
ereport ( ERROR ,
@ -1762,7 +1764,7 @@ jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
if ( PG_ARGISNULL ( 0 ) )
{
Oid arg_type ;
Oid arg_type ;
oldcontext = MemoryContextSwitchTo ( aggcontext ) ;
state = palloc ( sizeof ( JsonbAggState ) ) ;
@ -1950,8 +1952,9 @@ jsonb_object_agg_finalfn(PG_FUNCTION_ARGS)
/*
* We need to do a shallow clone of the argument ' s res field in case the
* final function is called more than once , so we avoid changing the
* it . A shallow clone is sufficient as we aren ' t going to change any of
* the values , just add the final object end marker .
* aggregate state value . A shallow clone is sufficient as we aren ' t
* going to change any of the values , just add the final object end
* marker .
*/
result . parseState = clone_parse_state ( arg - > res - > parseState ) ;