Fix JSON aggregates to work properly when final function is re-executed.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Dec 2014 20:02:37 +0000 (15:02 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Dec 2014 20:02:37 +0000 (15:02 -0500)
commit75ef435218fe4f6ce29d33e10f6f7a328c93f7e7
treeafd5894f062126cb191ab7e08e3a8037f1a96326
parent1511521a36f99a242f51c3bd0811cfcd53c5e63a
Fix JSON aggregates to work properly when final function is re-executed.

Davide S. reported that json_agg() sometimes produced multiple trailing
right brackets.  This turns out to be because json_agg_finalfn() attaches
the final right bracket, and was doing so by modifying the aggregate state
in-place.  That's verboten, though unfortunately it seems there's no way
for nodeAgg.c to check for such mistakes.

Fix that back to 9.3 where the broken code was introduced.  In 9.4 and
HEAD, likewise fix json_object_agg(), which had copied the erroneous logic.
Make some cosmetic cleanups as well.
src/backend/utils/adt/json.c