From fd025b1482223370cc10e82029468fdd99932368 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Thu, 13 Jul 2023 18:06:46 +0200 Subject: [PATCH 2/2] make the output generally usable, not just for datum_to_json[b] --- src/backend/utils/adt/jsonfuncs.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 764d48505b..a4bfa5e404 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -5705,16 +5705,10 @@ json_categorize_type(Oid typoid, bool is_jsonb, *outfuncoid = InvalidOid; - /* - * We need to get the output function for everything except date and - * timestamp types, booleans, array and composite types, json and jsonb, - * and non-builtin types where there's a cast to json. In this last case - * we return the oid of the cast function instead. - */ - switch (typoid) { case BOOLOID: + *outfuncoid = F_BOOLOUT; *tcategory = JSONTYPE_BOOL; break; @@ -5729,26 +5723,27 @@ json_categorize_type(Oid typoid, bool is_jsonb, break; case DATEOID: + *outfuncoid = F_DATE_OUT; *tcategory = JSONTYPE_DATE; break; case TIMESTAMPOID: + *outfuncoid = F_TIMESTAMP_OUT; *tcategory = JSONTYPE_TIMESTAMP; break; case TIMESTAMPTZOID: + *outfuncoid = F_TIMESTAMPTZ_OUT; *tcategory = JSONTYPE_TIMESTAMPTZ; break; case JSONOID: - if (!is_jsonb) - getTypeOutputInfo(typoid, outfuncoid, &typisvarlena); + getTypeOutputInfo(typoid, outfuncoid, &typisvarlena); *tcategory = JSONTYPE_JSON; break; case JSONBOID: - if (!is_jsonb) - getTypeOutputInfo(typoid, outfuncoid, &typisvarlena); + getTypeOutputInfo(typoid, outfuncoid, &typisvarlena); *tcategory = is_jsonb ? JSONTYPE_JSONB : JSONTYPE_JSON; break; @@ -5756,9 +5751,15 @@ json_categorize_type(Oid typoid, bool is_jsonb, /* Check for arrays and composites */ if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID || typoid == ANYCOMPATIBLEARRAYOID || typoid == RECORDARRAYOID) + { + *outfuncoid = F_ARRAY_OUT; *tcategory = JSONTYPE_ARRAY; + } else if (type_is_rowtype(typoid)) /* includes RECORDOID */ + { + *outfuncoid = F_RECORD_OUT; *tcategory = JSONTYPE_COMPOSITE; + } else { /* -- 2.30.2