Re: [GENERAL] Possible bug with row_to_json

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, Jack Christensen <jack(at)jackchristensen(dot)com>
Subject: Re: [GENERAL] Possible bug with row_to_json
Date: 2014-01-31 22:40:40
Message-ID: 20140131224040.GX19957@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Aug 13, 2013 at 05:34:12PM -0400, Tom Lane wrote:
> Further poking at this issue shows that there are related behaviors that
> aren't fixed by my proposed patch. The original complaint can be
> replicated in the regression database like this:
>
> select row_to_json(i8) from (select q1 as a, q2 from int8_tbl offset 0) i8;
>
> where we'd expect row_to_json to emit column names "a"/"q2" but we
> actually get "q1"/"q2". But consider this variant:
>
> select row_to_json(i8) from (select q1,q2 from int8_tbl offset 0) i8(x,y);
>
> Arguably, this should show column names x/y but what you get is q1/q2,
> even with my patch. Related cases include
>
> select row_to_json(v) from (values(1,2) limit 1) v(x,y);
> select row_to_json((select i8 from int8_tbl i8(x,y) limit 1));
>
> In the first two of those, the planner isn't bothering to install the
> column aliases into the plan's target lists. While we could fix that,
> it wouldn't help the last case, where the whole-row Var for "int8_tbl"
> is evaluated at scan level; the code for that is looking at the relation's
> tuple descriptor not the scan node's result descriptor. I'm not even
> sure what a clean fix for that case would look like.
>
> Since this behavior can also be demonstrated in 9.2 (and maybe further
> back using xml features?), I don't think we should consider it a
> blocker bug for 9.3. I'm planning to set it on the back burner for
> the moment and go worry about the planner's LATERAL bugs.

Where are we on this? I still see the failure:

regression=> select row_to_json(i8) from (select q1 as a, q2 from int8_tbl offset 0) i8;
row_to_json
------------------------------------------------
{"q1":123,"q2":456}
{"q1":123,"q2":4567890123456789}
{"q1":4567890123456789,"q2":123}
{"q1":4567890123456789,"q2":4567890123456789}
{"q1":4567890123456789,"q2":-4567890123456789}

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2014-01-31 23:00:05 Re: [GENERAL] Possible bug with row_to_json
Previous Message Ying He 2014-01-31 22:07:27 pg_basebackup on standby node failed

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2014-01-31 22:46:35 Re: WITH ORDINALITY planner improvements
Previous Message Bruce Momjian 2014-01-31 21:56:00 Re: [HACKERS] Insert result does not match record count