@@ -397,12 +397,70 @@ FROM rows q;
397397 "y":"txt3"}
398398(3 rows)
399399
400+ SELECT row_to_json(q,pretty := true)
401+ FROM rows q;
402+ row_to_json
403+ --------------
404+ {"x":1, +
405+ "y":"txt1"}
406+ {"x":2, +
407+ "y":"txt2"}
408+ {"x":3, +
409+ "y":"txt3"}
410+ (3 rows)
411+
400412SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false);
401413 row_to_json
402414-----------------------
403415 {"f1":[5,6,7,8,9,10]}
404416(1 row)
405417
418+ WITH x AS (SELECT a,b,c FROM (VALUES(10,20,30),
419+ (10,NULL, NULL),
420+ (NULL, NULL, NULL)) g(a,b,c))
421+ SELECT row_to_json(x, false, false) FROM x;
422+ row_to_json
423+ ------------------------------
424+ {"a":10,"b":20,"c":30}
425+ {"a":10,"b":null,"c":null}
426+ {"a":null,"b":null,"c":null}
427+ (3 rows)
428+
429+ WITH x AS (SELECT a,b,c FROM (VALUES(10,20,30),
430+ (10,NULL, NULL),
431+ (NULL, NULL, NULL)) g(a,b,c))
432+ SELECT row_to_json(x, false, true) FROM x;
433+ row_to_json
434+ ------------------------
435+ {"a":10,"b":20,"c":30}
436+ {"a":10}
437+ {}
438+ (3 rows)
439+
440+ WITH x AS (SELECT a,b,c FROM (VALUES(10,20,30),
441+ (10,NULL, NULL),
442+ (NULL, NULL, NULL)) g(a,b,c))
443+ SELECT row_to_json(x, ignore_nulls := true) FROM x;
444+ row_to_json
445+ ------------------------
446+ {"a":10,"b":20,"c":30}
447+ {"a":10}
448+ {}
449+ (3 rows)
450+
451+ WITH x AS (SELECT a,b,c FROM (VALUES(10,20,30),
452+ (10,NULL, NULL),
453+ (NULL, NULL, NULL)) g(a,b,c))
454+ SELECT row_to_json(x, ignore_nulls := true, pretty := true) FROM x;
455+ row_to_json
456+ -------------
457+ {"a":10, +
458+ "b":20, +
459+ "c":30}
460+ {"a":10}
461+ {}
462+ (3 rows)
463+
406464-- to_json, timestamps
407465select to_json(timestamp '2014-05-28 12:22:35.614298');
408466 to_json
0 commit comments