postgresql/src
Tom Lane bf7ca15875 Ensure that RowExprs and whole-row Vars produce the expected column names.
At one time it wasn't terribly important what column names were associated
with the fields of a composite Datum, but since the introduction of
operations like row_to_json(), it's important that looking up the rowtype
ID embedded in the Datum returns the column names that users would expect.
That did not work terribly well before this patch: you could get the column
names of the underlying table, or column aliases from any level of the
query, depending on minor details of the plan tree.  You could even get
totally empty field names, which is disastrous for cases like row_to_json().

To fix this for whole-row Vars, look to the RTE referenced by the Var, and
make sure its column aliases are applied to the rowtype associated with
the result Datums.  This is a tad scary because we might have to return
a transient RECORD type even though the Var is declared as having some
named rowtype.  In principle it should be all right because the record
type will still be physically compatible with the named rowtype; but
I had to weaken one Assert in ExecEvalConvertRowtype, and there might be
third-party code containing similar assumptions.

Similarly, RowExprs have to be willing to override the column names coming
from a named composite result type and produce a RECORD when the column
aliases visible at the site of the RowExpr differ from the underlying
table's column names.

In passing, revert the decision made in commit 398f70ec07 to add
an alias-list argument to ExecTypeFromExprList: better to provide that
functionality in a separate function.  This also reverts most of the code
changes in d685814835, which we don't need because we're no longer
depending on the tupdesc found in the child plan node's result slot to be
blessed.

Back-patch to 9.4, but not earlier, since this solution changes the results
in some cases that users might not have realized were buggy.  We'll apply a
more restricted form of this patch in older branches.
2014-11-10 15:21:09 -05:00
..
backend Ensure that RowExprs and whole-row Vars produce the expected column names. 2014-11-10 15:21:09 -05:00
bin Tab complete second argument to \c with role names. 2014-11-10 08:15:17 -05:00
common Small message fixes 2014-08-09 00:07:00 -04:00
include Ensure that RowExprs and whole-row Vars produce the expected column names. 2014-11-10 15:21:09 -05:00
interfaces Make ECPG test programs depend on "ecpg$(X)", not "ecpg". 2014-11-02 21:43:25 -05:00
makefiles MinGW: Use -static-libgcc when linking a DLL. 2014-10-21 22:55:47 -04:00
pl Re-remove dependency on the DLL of pythonxx.def file. 2014-11-02 21:43:30 -05:00
port Fix win32setlocale.c const-related warnings. 2014-11-02 21:43:20 -05:00
template Remove Alpha and Tru64 support. 2014-06-28 21:46:15 +02:00
test Ensure that RowExprs and whole-row Vars produce the expected column names. 2014-11-10 15:21:09 -05:00
timezone Support timezone abbreviations that sometimes change. 2014-10-16 15:22:10 -04:00
tools Add valgrind suppression for padding bytes in twophase records. 2014-09-01 15:59:44 +02:00
tutorial Adjust blank lines around PG_MODULE_MAGIC defines, for consistency 2014-07-10 14:02:08 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Add configure --enable-tap-tests option 2014-11-02 09:17:26 -05:00
Makefile.shlib Clarify .def file comments. 2014-11-02 21:43:33 -05:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00