mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-16 03:17:00 +08:00
Fix a couple of cases of JSON output.
First, as noted by Itagaki Takahiro, a datum of type JSON doesn't need to be escaped. Second, ensure that numeric output not in the form of a legal JSON number is quoted and escaped.
This commit is contained in:
@ -367,3 +367,33 @@ SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),
|
||||
{"f1":[5,6,7,8,9,10]}
|
||||
(1 row)
|
||||
|
||||
-- non-numeric output
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT 'NaN'::float8 AS "float8field") q;
|
||||
row_to_json
|
||||
-----------------------
|
||||
{"float8field":"NaN"}
|
||||
(1 row)
|
||||
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT 'Infinity'::float8 AS "float8field") q;
|
||||
row_to_json
|
||||
----------------------------
|
||||
{"float8field":"Infinity"}
|
||||
(1 row)
|
||||
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT '-Infinity'::float8 AS "float8field") q;
|
||||
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}}}
|
||||
(1 row)
|
||||
|
||||
|
||||
@ -97,3 +97,18 @@ SELECT row_to_json(q,true)
|
||||
FROM rows q;
|
||||
|
||||
SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false);
|
||||
|
||||
-- non-numeric output
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT 'NaN'::float8 AS "float8field") q;
|
||||
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT 'Infinity'::float8 AS "float8field") q;
|
||||
|
||||
SELECT row_to_json(q)
|
||||
FROM (SELECT '-Infinity'::float8 AS "float8field") q;
|
||||
|
||||
-- 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user