pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: AP <ap@zip.com.au>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
Date: Fri, 10 Jun 2016 21:06:33 +1000
Message-ID: <20160610110633.GG18838@zip.com.au> (raw )
In-Reply-To: <20160608103241.GE18838@zip.com.au >
References: <20160607014234.1381.95994@wrigleys.postgresql.org >
<CAB7nPqSneeh7NPhWM9zU3bEf9nY4N9hWTf9D_2Pj031OA6VH3Q@mail.gmail.com >
<CAEepm=0XMz1_Hy1twpsTd+2suQVrsCecjuWuAUYfdswWKQfG2g@mail.gmail.com >
<CAB7nPqRrdJeRcTGv+64xLZuGfVo9xvQyv+zu0_96SALiFrP=5g@mail.gmail.com >
<CAEepm=09NJt4-NAm9Z6j9fVOGh9nFqHJ852SoJf_dhq3eBeduw@mail.gmail.com >
<CAB7nPqQOuV+snOhWCF3enzYVv+66hWCo5ZGjBx1jd14Kb5-EwQ@mail.gmail.com >
<CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com >
<20160608103241.GE18838@zip.com.au >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Wed, Jun 08, 2016 at 08:32:41PM +1000, AP wrote:
> > So after thinking more on the matter, I'd rather give up on such
> > patches and recommend doing ::jsonb::text to be able to do equality
> > comparisons. If you want to get output similar to what jsonb is doing,
> > a simple cast with ::jsonb looks rather the saner way to go. This
> > induces more parsing cost, but that's the cost to pay...
>
> I think two things are being somewhat conflated:
>
> 1. the look of our JSON structures - we should be consistent here
> 2. the ordering of our JSON structures internally - a related (for the above
> use case issue) but, ultimately, seperate issue.
>
> 1 is easy to solve. JSON is JSON is JSON whether it's in a JSON data-type or
> JSONB and so no matter which it should look the same.
(docs snipped)
> As you can see, the key ordering is already covered. If you care, stick to JSON.
> If you don't, fly JSONB airlines.
>
> I think it's still worth doing #1 above and I'm willing to do the patch
> myself (it didn't occur to me how simple it was and I've been kicking myself
> at losing the opportunity to contribute :( :) ) if need be and if it'll fly .
Well I got bored and did it anyway. I checked all the functions in the doc page
and modified accordingly. My patch is, obviously, a superset of Michael's. :)
Interesting tidbit wrt this bit in the docs for JSON:
"Because the json type stores an exact copy of the input text, it will
preserve semantically-insignificant white space between tokens, as well
as the order of keys within JSON objects."
- https://www.postgresql.org/docs/current/static/datatype-json.html
json_strip_nulls doesn't appear to adhere to that:
moo=# select json_strip_nulls('{ "a":"b", "c":["a",2,-5,null], "d":{"e":"f", "true": false, "false": true, "val": null}}');
json_strip_nulls
-----------------------------------------------------------------------
{"a":"b","c":["a",2,-5,null],"d":{"e":"f","true":false,"false":true}}
(1 row)
Not sure if this should be fixed in-code or a note be made in the docs
of the exceptions.
Anyhow, patch attached.
Andrew
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
json-formatting.patch (text/x-diff, 31.1K) download
diff -aur postgresql-9.5-9.5.3.orig/src/backend/utils/adt/json.c postgresql-9.5-9.5.3/src/backend/utils/adt/json.c
--- postgresql-9.5-9.5.3.orig/src/backend/utils/adt/json.c 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/backend/utils/adt/json.c 2016-06-10 09:56:56.681634320 +1000
@@ -442,7 +442,7 @@
parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
{
/*
- * An object field is "fieldname" : value where value can be a scalar,
+ * An object field is "fieldname": value where value can be a scalar,
* object or array. Note: in user-facing docs and error messages, we
* generally call a field name a "key".
*/
@@ -1594,7 +1594,7 @@
Assert(dim < ndims);
- sep = use_line_feeds ? ",\n " : ",";
+ sep = use_line_feeds ? ",\n " : ", ";
appendStringInfoChar(result, '[');
@@ -1686,7 +1686,7 @@
bool needsep = false;
const char *sep;
- sep = use_line_feeds ? ",\n " : ",";
+ sep = use_line_feeds ? ",\n " : ", ";
td = DatumGetHeapTupleHeader(composite);
@@ -1719,7 +1719,7 @@
attname = NameStr(tupdesc->attrs[i]->attname);
escape_json(result, attname);
- appendStringInfoChar(result, ':');
+ appendStringInfoString(result, ": ");
val = heap_getattr(tuple, i + 1, tupdesc, &isnull);
@@ -2018,7 +2018,7 @@
json_categorize_type(arg_type, &state->val_category,
&state->val_output_func);
- appendStringInfoString(state->str, "{ ");
+ appendStringInfoString(state->str, "{");
}
else
{
@@ -2044,7 +2044,7 @@
datum_to_json(arg, false, state->str, state->key_category,
state->key_output_func, true);
- appendStringInfoString(state->str, " : ");
+ appendStringInfoString(state->str, ": ");
if (PG_ARGISNULL(2))
arg = (Datum) 0;
@@ -2075,7 +2075,7 @@
PG_RETURN_NULL();
/* Else return state with appropriate object terminator added */
- PG_RETURN_TEXT_P(catenate_stringinfo_string(state->str, " }"));
+ PG_RETURN_TEXT_P(catenate_stringinfo_string(state->str, "}"));
}
/*
@@ -2152,7 +2152,7 @@
add_json(arg, false, result, val_type, true);
- appendStringInfoString(result, " : ");
+ appendStringInfoString(result, ": ");
/* process value */
val_type = get_fn_expr_argtype(fcinfo->flinfo, i + 1);
@@ -2311,7 +2311,7 @@
if (i > 0)
appendStringInfoString(&result, ", ");
escape_json(&result, v);
- appendStringInfoString(&result, " : ");
+ appendStringInfoString(&result, ": ");
pfree(v);
if (in_nulls[i * 2 + 1])
appendStringInfoString(&result, "null");
@@ -2395,7 +2395,7 @@
if (i > 0)
appendStringInfoString(&result, ", ");
escape_json(&result, v);
- appendStringInfoString(&result, " : ");
+ appendStringInfoString(&result, ": ");
pfree(v);
if (val_nulls[i])
appendStringInfoString(&result, "null");
diff -aur postgresql-9.5-9.5.3.orig/src/backend/utils/adt/jsonfuncs.c postgresql-9.5-9.5.3/src/backend/utils/adt/jsonfuncs.c
--- postgresql-9.5-9.5.3.orig/src/backend/utils/adt/jsonfuncs.c 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/backend/utils/adt/jsonfuncs.c 2016-06-10 10:12:43.720160113 +1000
@@ -3147,7 +3147,7 @@
}
if (_state->strval->data[_state->strval->len - 1] != '{')
- appendStringInfoCharMacro(_state->strval, ',');
+ appendStringInfoString(_state->strval, ", ");
/*
* Unfortunately we don't have the quoted and escaped string any more, so
@@ -3155,7 +3155,7 @@
*/
escape_json(_state->strval, fname);
- appendStringInfoCharMacro(_state->strval, ':');
+ appendStringInfoString(_state->strval, ": ");
}
static void
@@ -3164,7 +3164,7 @@
StripnullState *_state = (StripnullState *) state;
if (_state->strval->data[_state->strval->len - 1] != '[')
- appendStringInfoCharMacro(_state->strval, ',');
+ appendStringInfoString(_state->strval, ", ");
}
static void
diff -aur postgresql-9.5-9.5.3.orig/src/test/regress/expected/copy2.out postgresql-9.5-9.5.3/src/test/regress/expected/copy2.out
--- postgresql-9.5-9.5.3.orig/src/test/regress/expected/copy2.out 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/test/regress/expected/copy2.out 2016-06-10 11:16:39.474352171 +1000
@@ -446,12 +446,12 @@
"check_con_tbl_check" CHECK (check_con_function(check_con_tbl.*))
copy check_con_tbl from stdin;
-NOTICE: input = {"f1":1}
+NOTICE: input = {"f1": 1}
CONTEXT: COPY check_con_tbl, line 1: "1"
-NOTICE: input = {"f1":null}
+NOTICE: input = {"f1": null}
CONTEXT: COPY check_con_tbl, line 2: "\N"
copy check_con_tbl from stdin;
-NOTICE: input = {"f1":0}
+NOTICE: input = {"f1": 0}
CONTEXT: COPY check_con_tbl, line 1: "0"
ERROR: new row for relation "check_con_tbl" violates check constraint "check_con_tbl_check"
DETAIL: Failing row contains (0).
diff -aur postgresql-9.5-9.5.3.orig/src/test/regress/expected/json.out postgresql-9.5-9.5.3/src/test/regress/expected/json.out
--- postgresql-9.5-9.5.3.orig/src/test/regress/expected/json.out 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/test/regress/expected/json.out 2016-06-10 11:10:55.089897082 +1000
@@ -281,17 +281,17 @@
(1 row)
SELECT array_to_json(array_agg(q),false) from (select x as b, x * 2 as c from generate_series(1,3) x) q;
- array_to_json
----------------------------------------------
- [{"b":1,"c":2},{"b":2,"c":4},{"b":3,"c":6}]
+ array_to_json
+--------------------------------------------------------
+ [{"b": 1, "c": 2}, {"b": 2, "c": 4}, {"b": 3, "c": 6}]
(1 row)
SELECT array_to_json(array_agg(q),true) from (select x as b, x * 2 as c from generate_series(1,3) x) q;
- array_to_json
------------------
- [{"b":1,"c":2},+
- {"b":2,"c":4},+
- {"b":3,"c":6}]
+ array_to_json
+--------------------
+ [{"b": 1, "c": 2},+
+ {"b": 2, "c": 4},+
+ {"b": 3, "c": 6}]
(1 row)
SELECT array_to_json(array_agg(q),false)
@@ -300,28 +300,28 @@
ROW(y.*,ARRAY[4,5,6])] AS z
FROM generate_series(1,2) x,
generate_series(4,5) y) q;
- array_to_json
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- [{"b":"a1","c":4,"z":[{"f1":1,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]},{"b":"a1","c":5,"z":[{"f1":1,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]},{"b":"a2","c":4,"z":[{"f1":2,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]},{"b":"a2","c":5,"z":[{"f1":2,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}]
+ array_to_json
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ [{"b": "a1", "c": 4, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}, {"b": "a1", "c": 5, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}, {"b": "a2", "c": 4, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}, {"b": "a2", "c": 5, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}]
(1 row)
SELECT array_to_json(array_agg(x),false) from generate_series(5,10) x;
- array_to_json
-----------------
- [5,6,7,8,9,10]
+ array_to_json
+---------------------
+ [5, 6, 7, 8, 9, 10]
(1 row)
SELECT array_to_json('{{1,5},{99,100}}'::int[]);
- array_to_json
-------------------
- [[1,5],[99,100]]
+ array_to_json
+---------------------
+ [[1, 5], [99, 100]]
(1 row)
-- row_to_json
SELECT row_to_json(row(1,'foo'));
- row_to_json
----------------------
- {"f1":1,"f2":"foo"}
+ row_to_json
+------------------------
+ {"f1": 1, "f2": "foo"}
(1 row)
SELECT row_to_json(q)
@@ -331,12 +331,12 @@
ROW(y.*,ARRAY[4,5,6])] AS z
FROM generate_series(1,2) x,
generate_series(4,5) y) q;
- row_to_json
---------------------------------------------------------------------
- {"b":"a1","c":4,"z":[{"f1":1,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}
- {"b":"a1","c":5,"z":[{"f1":1,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}
- {"b":"a2","c":4,"z":[{"f1":2,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}
- {"b":"a2","c":5,"z":[{"f1":2,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}
+ row_to_json
+------------------------------------------------------------------------------------
+ {"b": "a1", "c": 4, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}
+ {"b": "a1", "c": 5, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}
+ {"b": "a2", "c": 4, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}
+ {"b": "a2", "c": 5, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}
(4 rows)
SELECT row_to_json(q,true)
@@ -346,20 +346,20 @@
ROW(y.*,ARRAY[4,5,6])] AS z
FROM generate_series(1,2) x,
generate_series(4,5) y) q;
- row_to_json
------------------------------------------------------
- {"b":"a1", +
- "c":4, +
- "z":[{"f1":1,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}
- {"b":"a1", +
- "c":5, +
- "z":[{"f1":1,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}
- {"b":"a2", +
- "c":4, +
- "z":[{"f1":2,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}
- {"b":"a2", +
- "c":5, +
- "z":[{"f1":2,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}
+ row_to_json
+-----------------------------------------------------------------
+ {"b": "a1", +
+ "c": 4, +
+ "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}
+ {"b": "a1", +
+ "c": 5, +
+ "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}
+ {"b": "a2", +
+ "c": 4, +
+ "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}
+ {"b": "a2", +
+ "c": 5, +
+ "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}
(4 rows)
CREATE TEMP TABLE rows AS
@@ -367,20 +367,20 @@
FROM generate_series(1,3) AS x;
SELECT row_to_json(q,true)
FROM rows q;
- row_to_json
---------------
- {"x":1, +
- "y":"txt1"}
- {"x":2, +
- "y":"txt2"}
- {"x":3, +
- "y":"txt3"}
+ row_to_json
+---------------
+ {"x": 1, +
+ "y": "txt1"}
+ {"x": 2, +
+ "y": "txt2"}
+ {"x": 3, +
+ "y": "txt3"}
(3 rows)
SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false);
- row_to_json
------------------------
- {"f1":[5,6,7,8,9,10]}
+ row_to_json
+-----------------------------
+ {"f1": [5, 6, 7, 8, 9, 10]}
(1 row)
-- to_json, timestamps
@@ -455,61 +455,61 @@
ROW(y.*,ARRAY[4,5,6])] AS z
FROM generate_series(1,2) x,
generate_series(4,5) y) q;
- json_agg
------------------------------------------------------------------------
- [{"b":"a1","c":4,"z":[{"f1":1,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}, +
- {"b":"a1","c":5,"z":[{"f1":1,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}, +
- {"b":"a2","c":4,"z":[{"f1":2,"f2":[1,2,3]},{"f1":4,"f2":[4,5,6]}]}, +
- {"b":"a2","c":5,"z":[{"f1":2,"f2":[1,2,3]},{"f1":5,"f2":[4,5,6]}]}]
+ json_agg
+---------------------------------------------------------------------------------------
+ [{"b": "a1", "c": 4, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}, +
+ {"b": "a1", "c": 5, "z": [{"f1": 1, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}, +
+ {"b": "a2", "c": 4, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 4, "f2": [4, 5, 6]}]}, +
+ {"b": "a2", "c": 5, "z": [{"f1": 2, "f2": [1, 2, 3]}, {"f1": 5, "f2": [4, 5, 6]}]}]
(1 row)
SELECT json_agg(q ORDER BY x, y)
FROM rows q;
- json_agg
------------------------
- [{"x":1,"y":"txt1"}, +
- {"x":2,"y":"txt2"}, +
- {"x":3,"y":"txt3"}]
+ json_agg
+--------------------------
+ [{"x": 1, "y": "txt1"}, +
+ {"x": 2, "y": "txt2"}, +
+ {"x": 3, "y": "txt3"}]
(1 row)
UPDATE rows SET x = NULL WHERE x = 1;
SELECT json_agg(q ORDER BY x NULLS FIRST, y)
FROM rows q;
- json_agg
---------------------------
- [{"x":null,"y":"txt1"}, +
- {"x":2,"y":"txt2"}, +
- {"x":3,"y":"txt3"}]
+ json_agg
+-----------------------------
+ [{"x": null, "y": "txt1"}, +
+ {"x": 2, "y": "txt2"}, +
+ {"x": 3, "y": "txt3"}]
(1 row)
-- non-numeric output
SELECT row_to_json(q)
FROM (SELECT 'NaN'::float8 AS "float8field") q;
- row_to_json
------------------------
- {"float8field":"NaN"}
+ row_to_json
+------------------------
+ {"float8field": "NaN"}
(1 row)
SELECT row_to_json(q)
FROM (SELECT 'Infinity'::float8 AS "float8field") q;
- row_to_json
-----------------------------
- {"float8field":"Infinity"}
+ row_to_json
+-----------------------------
+ {"float8field": "Infinity"}
(1 row)
SELECT row_to_json(q)
FROM (SELECT '-Infinity'::float8 AS "float8field") q;
- row_to_json
------------------------------
- {"float8field":"-Infinity"}
+ row_to_json
+------------------------------
+ {"float8field": "-Infinity"}
(1 row)
-- json input
SELECT row_to_json(q)
FROM (SELECT '{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}'::json AS "jsonfield") q;
- row_to_json
-------------------------------------------------------------------
- {"jsonfield":{"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}}
+ row_to_json
+-------------------------------------------------------------------
+ {"jsonfield": {"a":1,"b": [2,3,4,"d","e","f"],"c":{"p":1,"q":2}}}
(1 row)
-- json extraction functions
@@ -1445,18 +1445,18 @@
(1 row)
SELECT json_build_object('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3, "y": [1,2,3]}');
- json_build_object
-----------------------------------------------------------------------------
- {"a" : 1, "b" : 1.2, "c" : true, "d" : null, "e" : {"x": 3, "y": [1,2,3]}}
+ json_build_object
+-----------------------------------------------------------------------
+ {"a": 1, "b": 1.2, "c": true, "d": null, "e": {"x": 3, "y": [1,2,3]}}
(1 row)
SELECT json_build_object(
'a', json_build_object('b',false,'c',99),
'd', json_build_object('e',array[9,8,7]::int[],
'f', (select row_to_json(r) from ( select relkind, oid::regclass as name from pg_class where relname = 'pg_class') r)));
- json_build_object
--------------------------------------------------------------------------------------------------
- {"a" : {"b" : false, "c" : 99}, "d" : {"e" : [9,8,7], "f" : {"relkind":"r","name":"pg_class"}}}
+ json_build_object
+------------------------------------------------------------------------------------------------
+ {"a": {"b": false, "c": 99}, "d": {"e": [9, 8, 7], "f": {"relkind": "r", "name": "pg_class"}}}
(1 row)
-- empty objects/arrays
@@ -1476,7 +1476,7 @@
SELECT json_build_object(1,2);
json_build_object
-------------------
- {"1" : 2}
+ {"1": 2}
(1 row)
-- keys must be scalar and not null
@@ -1495,15 +1495,15 @@
INSERT INTO foo VALUES (847003,'sub-alpha','GESS90');
SELECT json_build_object('turbines',json_object_agg(serial_num,json_build_object('name',name,'type',type)))
FROM foo;
- json_build_object
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- {"turbines" : { "847001" : {"name" : "t15", "type" : "GE1043"}, "847002" : {"name" : "t16", "type" : "GE1043"}, "847003" : {"name" : "sub-alpha", "type" : "GESS90"} }}
+ json_build_object
+-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"turbines": {"847001": {"name": "t15", "type": "GE1043"}, "847002": {"name": "t16", "type": "GE1043"}, "847003": {"name": "sub-alpha", "type": "GESS90"}}}
(1 row)
SELECT json_object_agg(name, type) FROM foo;
- json_object_agg
-----------------------------------------------------------------
- { "t15" : "GE1043", "t16" : "GE1043", "sub-alpha" : "GESS90" }
+ json_object_agg
+-----------------------------------------------------------
+ {"t15": "GE1043", "t16": "GE1043", "sub-alpha": "GESS90"}
(1 row)
INSERT INTO foo VALUES (999999, NULL, 'bar');
@@ -1526,16 +1526,16 @@
-- one dimension
SELECT json_object('{a,1,b,2,3,NULL,"d e f","a b c"}');
- json_object
--------------------------------------------------------
- {"a" : "1", "b" : "2", "3" : null, "d e f" : "a b c"}
+ json_object
+---------------------------------------------------
+ {"a": "1", "b": "2", "3": null, "d e f": "a b c"}
(1 row)
-- same but with two dimensions
SELECT json_object('{{a,1},{b,2},{3,NULL},{"d e f","a b c"}}');
- json_object
--------------------------------------------------------
- {"a" : "1", "b" : "2", "3" : null, "d e f" : "a b c"}
+ json_object
+---------------------------------------------------
+ {"a": "1", "b": "2", "3": null, "d e f": "a b c"}
(1 row)
-- odd number error
@@ -1552,9 +1552,9 @@
ERROR: wrong number of array subscripts
--two argument form of json_object
select json_object('{a,b,c,"d e f"}','{1,2,3,"a b c"}');
- json_object
-------------------------------------------------------
- {"a" : "1", "b" : "2", "c" : "3", "d e f" : "a b c"}
+ json_object
+--------------------------------------------------
+ {"a": "1", "b": "2", "c": "3", "d e f": "a b c"}
(1 row)
-- too many dimensions
@@ -1570,9 +1570,9 @@
ERROR: null value not allowed for object key
-- empty key is allowed
select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}');
- json_object
------------------------------------------------------
- {"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"}
+ json_object
+-------------------------------------------------
+ {"a": "1", "b": "2", "": "3", "d e f": "a b c"}
(1 row)
-- json_to_record and json_to_recordset
@@ -1641,27 +1641,27 @@
(1 row)
select json_strip_nulls('[1,2,null,3,4]');
- json_strip_nulls
-------------------
- [1,2,null,3,4]
+ json_strip_nulls
+--------------------
+ [1, 2, null, 3, 4]
(1 row)
select json_strip_nulls('{"a":1,"b":null,"c":[2,null,3],"d":{"e":4,"f":null}}');
- json_strip_nulls
-------------------------------------
- {"a":1,"c":[2,null,3],"d":{"e":4}}
+ json_strip_nulls
+--------------------------------------------
+ {"a": 1, "c": [2, null, 3], "d": {"e": 4}}
(1 row)
select json_strip_nulls('[1,{"a":1,"b":null,"c":2},3]');
- json_strip_nulls
----------------------
- [1,{"a":1,"c":2},3]
+ json_strip_nulls
+--------------------------
+ [1, {"a": 1, "c": 2}, 3]
(1 row)
-- an empty object is not null and should not be stripped
select json_strip_nulls('{"a": {"b": null, "c": null}, "d": {} }');
- json_strip_nulls
-------------------
- {"a":{},"d":{}}
+ json_strip_nulls
+--------------------
+ {"a": {}, "d": {}}
(1 row)
diff -aur postgresql-9.5-9.5.3.orig/src/test/regress/expected/jsonb.out postgresql-9.5-9.5.3/src/test/regress/expected/jsonb.out
--- postgresql-9.5-9.5.3.orig/src/test/regress/expected/jsonb.out 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/test/regress/expected/jsonb.out 2016-06-10 11:12:16.320891903 +1000
@@ -274,9 +274,9 @@
CONTEXT: JSON data, line 1:
-- make sure jsonb is passed through json generators without being escaped
SELECT array_to_json(ARRAY [jsonb '{"a":1}', jsonb '{"b":[2,3]}']);
- array_to_json
---------------------------
- [{"a": 1},{"b": [2, 3]}]
+ array_to_json
+---------------------------
+ [{"a": 1}, {"b": [2, 3]}]
(1 row)
-- to_jsonb, timestamps
diff -aur postgresql-9.5-9.5.3.orig/src/test/regress/expected/rangefuncs.out postgresql-9.5-9.5.3/src/test/regress/expected/rangefuncs.out
--- postgresql-9.5-9.5.3.orig/src/test/regress/expected/rangefuncs.out 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/test/regress/expected/rangefuncs.out 2016-06-10 11:17:16.540427758 +1000
@@ -68,12 +68,12 @@
(1 row)
select row_to_json(s.*) from generate_series(11,14) with ordinality s;
- row_to_json
--------------------------
- {"s":11,"ordinality":1}
- {"s":12,"ordinality":2}
- {"s":13,"ordinality":3}
- {"s":14,"ordinality":4}
+ row_to_json
+----------------------------
+ {"s": 11, "ordinality": 1}
+ {"s": 12, "ordinality": 2}
+ {"s": 13, "ordinality": 3}
+ {"s": 14, "ordinality": 4}
(4 rows)
-- ordinality vs. views
diff -aur postgresql-9.5-9.5.3.orig/src/test/regress/expected/rowtypes.out postgresql-9.5-9.5.3/src/test/regress/expected/rowtypes.out
--- postgresql-9.5-9.5.3.orig/src/test/regress/expected/rowtypes.out 2016-05-10 06:50:23.000000000 +1000
+++ postgresql-9.5-9.5.3/src/test/regress/expected/rowtypes.out 2016-06-10 11:25:19.720376200 +1000
@@ -502,110 +502,110 @@
-- (bug #11210 and other reports)
--
select row_to_json(i) from int8_tbl i;
- row_to_json
-------------------------------------------------
- {"q1":123,"q2":456}
- {"q1":123,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":123}
- {"q1":4567890123456789,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":-4567890123456789}
+ row_to_json
+---------------------------------------------------
+ {"q1": 123, "q2": 456}
+ {"q1": 123, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": 123}
+ {"q1": 4567890123456789, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": -4567890123456789}
(5 rows)
select row_to_json(i) from int8_tbl i(x,y);
- row_to_json
-----------------------------------------------
- {"x":123,"y":456}
- {"x":123,"y":4567890123456789}
- {"x":4567890123456789,"y":123}
- {"x":4567890123456789,"y":4567890123456789}
- {"x":4567890123456789,"y":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"x": 123, "y": 456}
+ {"x": 123, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": 123}
+ {"x": 4567890123456789, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": -4567890123456789}
(5 rows)
create temp view vv1 as select * from int8_tbl;
select row_to_json(i) from vv1 i;
- row_to_json
-------------------------------------------------
- {"q1":123,"q2":456}
- {"q1":123,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":123}
- {"q1":4567890123456789,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":-4567890123456789}
+ row_to_json
+---------------------------------------------------
+ {"q1": 123, "q2": 456}
+ {"q1": 123, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": 123}
+ {"q1": 4567890123456789, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": -4567890123456789}
(5 rows)
select row_to_json(i) from vv1 i(x,y);
- row_to_json
-----------------------------------------------
- {"x":123,"y":456}
- {"x":123,"y":4567890123456789}
- {"x":4567890123456789,"y":123}
- {"x":4567890123456789,"y":4567890123456789}
- {"x":4567890123456789,"y":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"x": 123, "y": 456}
+ {"x": 123, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": 123}
+ {"x": 4567890123456789, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1, q2 from int8_tbl) as ss;
- row_to_json
-------------------------------------------------
- {"q1":123,"q2":456}
- {"q1":123,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":123}
- {"q1":4567890123456789,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":-4567890123456789}
+ row_to_json
+---------------------------------------------------
+ {"q1": 123, "q2": 456}
+ {"q1": 123, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": 123}
+ {"q1": 4567890123456789, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1, q2 from int8_tbl offset 0) as ss;
- row_to_json
-------------------------------------------------
- {"q1":123,"q2":456}
- {"q1":123,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":123}
- {"q1":4567890123456789,"q2":4567890123456789}
- {"q1":4567890123456789,"q2":-4567890123456789}
+ row_to_json
+---------------------------------------------------
+ {"q1": 123, "q2": 456}
+ {"q1": 123, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": 123}
+ {"q1": 4567890123456789, "q2": 4567890123456789}
+ {"q1": 4567890123456789, "q2": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1 as a, q2 as b from int8_tbl) as ss;
- row_to_json
-----------------------------------------------
- {"a":123,"b":456}
- {"a":123,"b":4567890123456789}
- {"a":4567890123456789,"b":123}
- {"a":4567890123456789,"b":4567890123456789}
- {"a":4567890123456789,"b":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"a": 123, "b": 456}
+ {"a": 123, "b": 4567890123456789}
+ {"a": 4567890123456789, "b": 123}
+ {"a": 4567890123456789, "b": 4567890123456789}
+ {"a": 4567890123456789, "b": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1 as a, q2 as b from int8_tbl offset 0) as ss;
- row_to_json
-----------------------------------------------
- {"a":123,"b":456}
- {"a":123,"b":4567890123456789}
- {"a":4567890123456789,"b":123}
- {"a":4567890123456789,"b":4567890123456789}
- {"a":4567890123456789,"b":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"a": 123, "b": 456}
+ {"a": 123, "b": 4567890123456789}
+ {"a": 4567890123456789, "b": 123}
+ {"a": 4567890123456789, "b": 4567890123456789}
+ {"a": 4567890123456789, "b": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1 as a, q2 as b from int8_tbl) as ss(x,y);
- row_to_json
-----------------------------------------------
- {"x":123,"y":456}
- {"x":123,"y":4567890123456789}
- {"x":4567890123456789,"y":123}
- {"x":4567890123456789,"y":4567890123456789}
- {"x":4567890123456789,"y":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"x": 123, "y": 456}
+ {"x": 123, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": 123}
+ {"x": 4567890123456789, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": -4567890123456789}
(5 rows)
select row_to_json(ss) from
(select q1 as a, q2 as b from int8_tbl offset 0) as ss(x,y);
- row_to_json
-----------------------------------------------
- {"x":123,"y":456}
- {"x":123,"y":4567890123456789}
- {"x":4567890123456789,"y":123}
- {"x":4567890123456789,"y":4567890123456789}
- {"x":4567890123456789,"y":-4567890123456789}
+ row_to_json
+-------------------------------------------------
+ {"x": 123, "y": 456}
+ {"x": 123, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": 123}
+ {"x": 4567890123456789, "y": 4567890123456789}
+ {"x": 4567890123456789, "y": -4567890123456789}
(5 rows)
explain (costs off)
@@ -622,38 +622,38 @@
select row_to_json(q) from
(select thousand, tenthous from tenk1
where thousand = 42 and tenthous < 2000 offset 0) q;
- row_to_json
----------------------------------
- {"thousand":42,"tenthous":42}
- {"thousand":42,"tenthous":1042}
+ row_to_json
+------------------------------------
+ {"thousand": 42, "tenthous": 42}
+ {"thousand": 42, "tenthous": 1042}
(2 rows)
select row_to_json(q) from
(select thousand as x, tenthous as y from tenk1
where thousand = 42 and tenthous < 2000 offset 0) q;
- row_to_json
--------------------
- {"x":42,"y":42}
- {"x":42,"y":1042}
+ row_to_json
+----------------------
+ {"x": 42, "y": 42}
+ {"x": 42, "y": 1042}
(2 rows)
select row_to_json(q) from
(select thousand as x, tenthous as y from tenk1
where thousand = 42 and tenthous < 2000 offset 0) q(a,b);
- row_to_json
--------------------
- {"a":42,"b":42}
- {"a":42,"b":1042}
+ row_to_json
+----------------------
+ {"a": 42, "b": 42}
+ {"a": 42, "b": 1042}
(2 rows)
create temp table tt1 as select * from int8_tbl limit 2;
create temp table tt2 () inherits(tt1);
insert into tt2 values(0,0);
select row_to_json(r) from (select q2,q1 from tt1 offset 0) r;
- row_to_json
-----------------------------------
- {"q2":456,"q1":123}
- {"q2":4567890123456789,"q1":123}
- {"q2":0,"q1":0}
+ row_to_json
+-------------------------------------
+ {"q2": 456, "q1": 123}
+ {"q2": 4567890123456789, "q1": 123}
+ {"q2": 0, "q1": 0}
(3 rows)
view thread (9+ messages)
Message-ID: <20160610110633.GG18838@zip.com.au>
Permalink: ../20160610110633.GG18838@zip.com.au/
Also on: postgresql.org/message-id/20160610110633.GG18838@zip.com.au
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: ap@zip.com.au, michael.paquier@gmail.com, thomas.munro@enterprisedb.com
Subject: Re: BUG #14178: output of jsonb_object and json_object doesn't match textually
In-Reply-To: <20160610110633.GG18838@zip.com.au>
References: <20160607014234.1381.95994@wrigleys.postgresql.org> <CAB7nPqSneeh7NPhWM9zU3bEf9nY4N9hWTf9D_2Pj031OA6VH3Q@mail.gmail.com> <CAEepm=0XMz1_Hy1twpsTd+2suQVrsCecjuWuAUYfdswWKQfG2g@mail.gmail.com> <CAB7nPqRrdJeRcTGv+64xLZuGfVo9xvQyv+zu0_96SALiFrP=5g@mail.gmail.com> <CAEepm=09NJt4-NAm9Z6j9fVOGh9nFqHJ852SoJf_dhq3eBeduw@mail.gmail.com> <CAB7nPqQOuV+snOhWCF3enzYVv+66hWCo5ZGjBx1jd14Kb5-EwQ@mail.gmail.com> <CAB7nPqReds5Hf+_Sd=sLT5D59AHnifg18QTWTe--Wh=fqzaqsg@mail.gmail.com> <20160608103241.GE18838@zip.com.au> <20160610110633.GG18838@zip.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox