commit 49695b5ef165b1736fab65d6443640c5529b6338 Author: Alvaro Herrera AuthorDate: Thu Apr 20 16:26:27 2017 -0300 CommitDate: Thu Apr 20 16:26:27 2017 -0300 Fix extstats output funcs to emit valid JSON diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index 0890514bf7..cbc2a3c6c3 100644 --- a/src/backend/statistics/dependencies.c +++ b/src/backend/statistics/dependencies.c @@ -696,7 +696,7 @@ pg_dependencies_out(PG_FUNCTION_ARGS) MVDependencies *dependencies = statext_dependencies_deserialize(data); initStringInfo(&str); - appendStringInfoChar(&str, '['); + appendStringInfoChar(&str, '{'); for (i = 0; i < dependencies->ndeps; i++) { @@ -705,7 +705,7 @@ pg_dependencies_out(PG_FUNCTION_ARGS) if (i > 0) appendStringInfoString(&str, ", "); - appendStringInfoChar(&str, '{'); + appendStringInfoChar(&str, '"'); for (j = 0; j < dependency->nattributes; j++) { if (j == dependency->nattributes - 1) @@ -715,11 +715,10 @@ pg_dependencies_out(PG_FUNCTION_ARGS) appendStringInfo(&str, "%d", dependency->attributes[j]); } - appendStringInfo(&str, " : %f", dependency->degree); - appendStringInfoChar(&str, '}'); + appendStringInfo(&str, "\": %f", dependency->degree); } - appendStringInfoChar(&str, ']'); + appendStringInfoChar(&str, '}'); PG_RETURN_CSTRING(str.data); } diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.c index b77113fb39..362c912b2c 100644 --- a/src/backend/statistics/mvdistinct.c +++ b/src/backend/statistics/mvdistinct.c @@ -354,21 +354,29 @@ pg_ndistinct_out(PG_FUNCTION_ARGS) StringInfoData str; initStringInfo(&str); - appendStringInfoChar(&str, '['); + appendStringInfoChar(&str, '{'); for (i = 0; i < ndist->nitems; i++) { MVNDistinctItem item = ndist->items[i]; + int x = -1; + bool first = true; if (i > 0) appendStringInfoString(&str, ", "); - appendStringInfoChar(&str, '{'); - outBitmapset(&str, item.attrs); - appendStringInfo(&str, ", %f}", item.ndistinct); + appendStringInfoChar(&str, '"'); + while ((x = bms_next_member(item.attrs, x)) >= 0) + { + if (!first) + appendStringInfoString(&str, ", "); + first = false; + appendStringInfo(&str, "%d", x); + } + appendStringInfo(&str, "\": %d", (int) item.ndistinct); } - appendStringInfoChar(&str, ']'); + appendStringInfoChar(&str, '}'); PG_RETURN_CSTRING(str.data); }