@@ -79,8 +79,7 @@ static void report_invalid_token(JsonLexContext *lex);
79
79
static int report_json_context (JsonLexContext * lex );
80
80
static char * extract_mb_char (char * s );
81
81
static void composite_to_json (Datum composite , StringInfo result ,
82
- bool use_line_feeds ,
83
- bool ignore_nulls );
82
+ bool use_line_feeds );
84
83
static void array_dim_to_json (StringInfo result , int dim , int ndims , int * dims ,
85
84
Datum * vals , bool * nulls , int * valcount ,
86
85
JsonTypeCategory tcategory , Oid outfuncoid ,
@@ -1366,7 +1365,7 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
1366
1365
array_to_json_internal (val , result , false);
1367
1366
break ;
1368
1367
case JSONTYPE_COMPOSITE :
1369
- composite_to_json (val , result , false, false );
1368
+ composite_to_json (val , result , false);
1370
1369
break ;
1371
1370
case JSONTYPE_BOOL :
1372
1371
outputstr = DatumGetBool (val ) ? "true" : "false" ;
@@ -1591,8 +1590,7 @@ array_to_json_internal(Datum array, StringInfo result, bool use_line_feeds)
1591
1590
* Turn a composite / record into JSON.
1592
1591
*/
1593
1592
static void
1594
- composite_to_json (Datum composite , StringInfo result , bool use_line_feeds ,
1595
- bool ignore_nulls )
1593
+ composite_to_json (Datum composite , StringInfo result , bool use_line_feeds )
1596
1594
{
1597
1595
HeapTupleHeader td ;
1598
1596
Oid tupType ;
@@ -1631,12 +1629,6 @@ composite_to_json(Datum composite, StringInfo result, bool use_line_feeds,
1631
1629
if (tupdesc -> attrs [i ]-> attisdropped )
1632
1630
continue ;
1633
1631
1634
- val = heap_getattr (tuple , i + 1 , tupdesc , & isnull );
1635
-
1636
- /* Don't serialize NULL field when we don't want it */
1637
- if (isnull && ignore_nulls )
1638
- continue ;
1639
-
1640
1632
if (needsep )
1641
1633
appendStringInfoString (result , sep );
1642
1634
needsep = true;
@@ -1645,6 +1637,8 @@ composite_to_json(Datum composite, StringInfo result, bool use_line_feeds,
1645
1637
escape_json (result , attname );
1646
1638
appendStringInfoChar (result , ':' );
1647
1639
1640
+ val = heap_getattr (tuple , i + 1 , tupdesc , & isnull );
1641
+
1648
1642
if (isnull )
1649
1643
{
1650
1644
tcategory = JSONTYPE_NULL ;
@@ -1693,10 +1687,26 @@ add_json(Datum val, bool is_null, StringInfo result,
1693
1687
}
1694
1688
1695
1689
/*
1696
- * SQL function array_to_json(row, prettybool )
1690
+ * SQL function array_to_json(row)
1697
1691
*/
1698
1692
extern Datum
1699
1693
array_to_json (PG_FUNCTION_ARGS )
1694
+ {
1695
+ Datum array = PG_GETARG_DATUM (0 );
1696
+ StringInfo result ;
1697
+
1698
+ result = makeStringInfo ();
1699
+
1700
+ array_to_json_internal (array , result , false);
1701
+
1702
+ PG_RETURN_TEXT_P (cstring_to_text_with_len (result -> data , result -> len ));
1703
+ }
1704
+
1705
+ /*
1706
+ * SQL function array_to_json(row, prettybool)
1707
+ */
1708
+ extern Datum
1709
+ array_to_json_pretty (PG_FUNCTION_ARGS )
1700
1710
{
1701
1711
Datum array = PG_GETARG_DATUM (0 );
1702
1712
bool use_line_feeds = PG_GETARG_BOOL (1 );
@@ -1710,19 +1720,34 @@ array_to_json(PG_FUNCTION_ARGS)
1710
1720
}
1711
1721
1712
1722
/*
1713
- * SQL function row_to_json(rowval record, pretty bool, ignore_nulls bool )
1723
+ * SQL function row_to_json(row )
1714
1724
*/
1715
1725
extern Datum
1716
1726
row_to_json (PG_FUNCTION_ARGS )
1727
+ {
1728
+ Datum array = PG_GETARG_DATUM (0 );
1729
+ StringInfo result ;
1730
+
1731
+ result = makeStringInfo ();
1732
+
1733
+ composite_to_json (array , result , false);
1734
+
1735
+ PG_RETURN_TEXT_P (cstring_to_text_with_len (result -> data , result -> len ));
1736
+ }
1737
+
1738
+ /*
1739
+ * SQL function row_to_json(row, prettybool)
1740
+ */
1741
+ extern Datum
1742
+ row_to_json_pretty (PG_FUNCTION_ARGS )
1717
1743
{
1718
1744
Datum array = PG_GETARG_DATUM (0 );
1719
1745
bool use_line_feeds = PG_GETARG_BOOL (1 );
1720
- bool ignore_nulls = PG_GETARG_BOOL (2 );
1721
1746
StringInfo result ;
1722
1747
1723
1748
result = makeStringInfo ();
1724
1749
1725
- composite_to_json (array , result , use_line_feeds , ignore_nulls );
1750
+ composite_to_json (array , result , use_line_feeds );
1726
1751
1727
1752
PG_RETURN_TEXT_P (cstring_to_text_with_len (result -> data , result -> len ));
1728
1753
}
0 commit comments