Re: Recent 11.16 release change

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Brinzila <briuz001(at)umn(dot)edu>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Recent 11.16 release change
Date: 2022-06-14 21:23:15
Message-ID: 151155.1655241795@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Daniel Brinzila <briuz001(at)umn(dot)edu> writes:
> I am a bit confused as to the following change:
> Stop using query-provided column aliases for the columns of whole-row
> variables that refer to plain tables (Tom Lane)

> Could someone please give an example of this scenario, one that works in
> 11.15 and another for 11.16 after the recent change.

Here's the regression test example that changed behavior in that commit:

regression=# select row_to_json(i) from int8_tbl i(x,y);
row_to_json
------------------------------------------------
{"q1":123,"q2":456}
{"q1":123,"q2":4567890123456789}
{"q1":4567890123456789,"q2":123}
{"q1":4567890123456789,"q2":4567890123456789}
{"q1":4567890123456789,"q2":-4567890123456789}
(5 rows)

The fields of the JSON output used to be labeled "x" and "y", after
the column aliases of the FROM item. But now that doesn't work and
you get the table's original column names (which happen to be "q1"
and "q2" in this test case).

The workaround proposed in the release note is to do this if you
need to relabel the columns of the whole-row variable "i":

regression=# select row_to_json(i) from (select * from int8_tbl) i(x,y);
row_to_json
----------------------------------------------
{"x":123,"y":456}
{"x":123,"y":4567890123456789}
{"x":4567890123456789,"y":123}
{"x":4567890123456789,"y":4567890123456789}
{"x":4567890123456789,"y":-4567890123456789}
(5 rows)

With the extra sub-select, "i" is no longer of the named composite
type associated with int8_tbl, but of an anonymous record type,
so it can have the column names you want.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Brinzila 2022-06-14 21:35:12 Re: Recent 11.16 release change
Previous Message Daniel Brinzila 2022-06-14 19:30:47 Recent 11.16 release change