* array_out : * takes the internal representation of an array and returns a string * containing the array in its external format. */
| 1016 | * containing the array in its external format. |
| 1017 | */ |
| 1018 | Datum |
| 1019 | array_out(PG_FUNCTION_ARGS) |
| 1020 | { |
| 1021 | AnyArrayType *v = PG_GETARG_ANY_ARRAY_P(0); |
| 1022 | Oid element_type = AARR_ELEMTYPE(v); |
| 1023 | int typlen; |
| 1024 | bool typbyval; |
| 1025 | char typalign; |
| 1026 | char typdelim; |
| 1027 | char *p, |
| 1028 | *tmp, |
| 1029 | *retval, |
| 1030 | **values, |
| 1031 | dims_str[(MAXDIM * 33) + 2]; |
| 1032 | |
| 1033 | /* |
| 1034 | * 33 per dim since we assume 15 digits per number + ':' +'[]' |
| 1035 | * |
| 1036 | * +2 allows for assignment operator + trailing null |
| 1037 | */ |
| 1038 | bool *needquotes, |
| 1039 | needdims = false; |
| 1040 | size_t overall_length; |
| 1041 | int nitems, |
| 1042 | i, |
| 1043 | j, |
| 1044 | k, |
| 1045 | indx[MAXDIM]; |
| 1046 | int ndim, |
| 1047 | *dims, |
| 1048 | *lb; |
| 1049 | array_iter iter; |
| 1050 | ArrayMetaState *my_extra; |
| 1051 | |
| 1052 | /* |
| 1053 | * We arrange to look up info about element type, including its output |
| 1054 | * conversion proc, only once per series of calls, assuming the element |
| 1055 | * type doesn't change underneath us. |
| 1056 | */ |
| 1057 | my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra; |
| 1058 | if (my_extra == NULL) |
| 1059 | { |
| 1060 | fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt, |
| 1061 | sizeof(ArrayMetaState)); |
| 1062 | my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra; |
| 1063 | my_extra->element_type = ~element_type; |
| 1064 | } |
| 1065 | |
| 1066 | if (my_extra->element_type != element_type) |
| 1067 | { |
| 1068 | /* |
| 1069 | * Get info about element type, including its output conversion proc |
| 1070 | */ |
| 1071 | get_type_io_data(element_type, IOFunc_output, |
| 1072 | &my_extra->typlen, &my_extra->typbyval, |
| 1073 | &my_extra->typalign, &my_extra->typdelim, |
| 1074 | &my_extra->typioparam, &my_extra->typiofunc); |
| 1075 | fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc, |
no test coverage detected