1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-18 02:02:55 +03:00

extstats: change output functions to emit valid JSON

Manipulating extended statistics is more convenient as JSON than the
current ad-hoc format, so let's change before it's too late.

Discussion: https://postgr.es/m/20170420193828.k3fliiock5hdnehn@alvherre.pgsql
This commit is contained in:
Alvaro Herrera
2017-05-02 18:49:32 -03:00
parent e950024066
commit 93bbeec6a2
4 changed files with 28 additions and 33 deletions

View File

@@ -354,21 +354,26 @@ 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);
while ((x = bms_next_member(item.attrs, x)) >= 0)
{
appendStringInfo(&str, "%s%d", first ? "\"" : ", ", x);
first = false;
}
appendStringInfo(&str, "\": %d", (int) item.ndistinct);
}
appendStringInfoChar(&str, ']');
appendStringInfoChar(&str, '}');
PG_RETURN_CSTRING(str.data);
}