Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Andrew Dunstan
On 10/17/2013 10:23 AM, Alvaro Herrera wrote: Oskari Saarenmaa wrote: @@ -1241,8 +1241,8 @@ hstore_to_json_loose(PG_FUNCTION_ARGS) if (count == 0) { - out = palloc(1); - *out = '\0'; + out = palloc(3); + memcpy(out, "{}", 3

Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Oskari Saarenmaa
On 17/10/13 17:23, Alvaro Herrera wrote: Oskari Saarenmaa wrote: @@ -1241,8 +1241,8 @@ hstore_to_json_loose(PG_FUNCTION_ARGS) if (count == 0) { - out = palloc(1); - *out = '\0'; + out = palloc(3); + memcpy(out, "{}", 3);

Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Alvaro Herrera
Oskari Saarenmaa wrote: > @@ -1241,8 +1241,8 @@ hstore_to_json_loose(PG_FUNCTION_ARGS) > > if (count == 0) > { > - out = palloc(1); > - *out = '\0'; > + out = palloc(3); > + memcpy(out, "{}", 3); > PG_RETURN_TEXT_P(cstring

Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Andrew Dunstan
On 10/17/2013 08:20 AM, Robert Haas wrote: On Wed, Oct 16, 2013 at 12:02 PM, Oskari Saarenmaa wrote: hstore_to_json used to return an empty string for empty hstores, but that is not correct as an empty string is not valid json and calling row_to_json() on rows which have empty hstores will gen

Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Merlin Moncure
On Thu, Oct 17, 2013 at 7:20 AM, Robert Haas wrote: > On Wed, Oct 16, 2013 at 12:02 PM, Oskari Saarenmaa wrote: >> hstore_to_json used to return an empty string for empty hstores, but >> that is not correct as an empty string is not valid json and calling >> row_to_json() on rows which have empty

Re: [HACKERS] [PATCH] hstore_to_json: empty hstores must return empty json objects

2013-10-17 Thread Robert Haas
On Wed, Oct 16, 2013 at 12:02 PM, Oskari Saarenmaa wrote: > hstore_to_json used to return an empty string for empty hstores, but > that is not correct as an empty string is not valid json and calling > row_to_json() on rows which have empty hstores will generate invalid > json for the entire row.