* Turn an array into JSON. */
| 983 | * Turn an array into JSON. |
| 984 | */ |
| 985 | static void |
| 986 | array_to_jsonb_internal(Datum array, JsonbInState *result) |
| 987 | { |
| 988 | ArrayType *v = DatumGetArrayTypeP(array); |
| 989 | Oid element_type = ARR_ELEMTYPE(v); |
| 990 | int *dim; |
| 991 | int ndim; |
| 992 | int nitems; |
| 993 | int count = 0; |
| 994 | Datum *elements; |
| 995 | bool *nulls; |
| 996 | int16 typlen; |
| 997 | bool typbyval; |
| 998 | char typalign; |
| 999 | JsonbTypeCategory tcategory; |
| 1000 | Oid outfuncoid; |
| 1001 | |
| 1002 | ndim = ARR_NDIM(v); |
| 1003 | dim = ARR_DIMS(v); |
| 1004 | nitems = ArrayGetNItems(ndim, dim); |
| 1005 | |
| 1006 | if (nitems <= 0) |
| 1007 | { |
| 1008 | result->res = pushJsonbValue(&result->parseState, WJB_BEGIN_ARRAY, NULL); |
| 1009 | result->res = pushJsonbValue(&result->parseState, WJB_END_ARRAY, NULL); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | get_typlenbyvalalign(element_type, |
| 1014 | &typlen, &typbyval, &typalign); |
| 1015 | |
| 1016 | jsonb_categorize_type(element_type, |
| 1017 | &tcategory, &outfuncoid); |
| 1018 | |
| 1019 | deconstruct_array(v, element_type, typlen, typbyval, |
| 1020 | typalign, &elements, &nulls, |
| 1021 | &nitems); |
| 1022 | |
| 1023 | array_dim_to_jsonb(result, 0, ndim, dim, elements, nulls, &count, tcategory, |
| 1024 | outfuncoid); |
| 1025 | |
| 1026 | pfree(elements); |
| 1027 | pfree(nulls); |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Turn a composite / record into JSON. |
no test coverage detected