Return NULL from json_object_agg if it gets no rows.
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 25 Sep 2014 12:18:18 +0000 (08:18 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 25 Sep 2014 12:18:18 +0000 (08:18 -0400)
This makes it consistent with the docs and with all other builtin
aggregates apart from count().

src/backend/utils/adt/json.c

index 19d74014ef532b5c96af3fe6ab5ff2d54c1ae5e1..c52f6732b054b626d93efa44ffad854c72c84332 100644 (file)
@@ -1948,7 +1948,7 @@ json_object_agg_finalfn(PG_FUNCTION_ARGS)
        state = PG_ARGISNULL(0) ? NULL : (StringInfo) PG_GETARG_POINTER(0);
 
        if (state == NULL)
-               PG_RETURN_TEXT_P(cstring_to_text("{}"));
+               PG_RETURN_NULL();
 
        appendStringInfoString(state, " }");