row_to_json(), NULL values, and AS - Mailing list pgsql-bugs

From Neil Conway
Subject row_to_json(), NULL values, and AS
Date
Msg-id CAOW5sYa3Wp7KozCuzjOdw6PiOYPi6D=VvRybtH2S=2C0SVmRmA@mail.gmail.com
Whole thread Raw
Responses Re: row_to_json(), NULL values, and AS  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Hi,

The following behavior does not seem self-consistent to me:

postgres=# select json_agg(row_to_json(x)) from (select *, null from
generate_series(1, 3)) x;
                                                       json_agg

-----------------------------------------------------------------------------------------------------------------------
 [{"generate_series":1,"?column?":null},
{"generate_series":2,"?column?":null},
{"generate_series":3,"?column?":null}]
(1 row)

postgres=# select json_agg(row_to_json(x)) from (select *,
row_to_json(null) as jjj from generate_series(1, 3)) x;
                                                json_agg
--------------------------------------------------------------------------------------------------------
 [{"generate_series":1,"jjj":null}, {"generate_series":2,"jjj":null},
{"generate_series":3,"jjj":null}]
(1 row)

postgres=# select json_agg(row_to_json(x)) from (select *,
row_to_json(null) from generate_series(1, 3)) x;
      json_agg
--------------------
 [null, null, null]
(1 row)

In particular, it is unclear to me why removing the targetlist alias
in the subquery in the third example should change the result set of
the parent query.

Thanks,
Neil


pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #15242: JSON functions not recognizing JSON
Next
From: Tom Lane
Date:
Subject: Re: row_to_json(), NULL values, and AS