postgresql/src
Tom Lane 0b78106cd4 Fix reporting of column typmods for multi-row VALUES constructs.
expandRTE() and get_rte_attribute_type() reported the exprType() and
exprTypmod() values of the expressions in the first row of the VALUES as
being the column type/typmod returned by the VALUES RTE.  That's fine for
the data type, since we coerce all expressions in a column to have the same
common type.  But we don't coerce them to have a common typmod, so it was
possible for rows after the first one to return values that violate the
claimed column typmod.  This leads to the incorrect result seen in bug
#14448 from Hassan Mahmood, as well as some other corner-case misbehaviors.

The desired behavior is the same as we use in other type-unification
cases: report the common typmod if there is one, but otherwise return -1
indicating no particular constraint.  It's cheap for transformValuesClause
to determine the common typmod while transforming a multi-row VALUES, but
it'd be less cheap for expandRTE() and get_rte_attribute_type() to
re-determine that info every time they're asked --- possibly a lot less
cheap, if the VALUES has many rows.  Therefore, the best fix is to record
the common typmods explicitly in a list in the VALUES RTE, as we were
already doing for column collations.  This looks quite a bit like what
we're doing for CTE RTEs, so we can save a little bit of space and code by
unifying the representation for those two RTE types.  They both now share
coltypes/coltypmods/colcollations fields.  (At some point it might seem
desirable to populate those fields for all RTE types; but right now it
looks like constructing them for other RTE types would add more code and
cycles than it would save.)

The RTE change requires a catversion bump, so this fix is only usable
in HEAD.  If we fix this at all in the back branches, the patch will
need to look quite different.

Report: https://postgr.es/m/20161205143037.4377.60754@wrigleys.postgresql.org
Discussion: https://postgr.es/m/27429.1480968538@sss.pgh.pa.us
2016-12-08 11:40:02 -05:00
..
backend Fix reporting of column typmods for multi-row VALUES constructs. 2016-12-08 11:40:02 -05:00
bin Fix quoting and a compiler warning in dumping partitions. 2016-12-08 14:10:10 +02:00
common Rename "pg_xlog" directory to "pg_wal". 2016-10-20 11:32:18 -04:00
fe_utils Restore psql's SIGPIPE setting if popen() fails. 2016-12-07 12:39:24 -05:00
include Fix reporting of column typmods for multi-row VALUES constructs. 2016-12-08 11:40:02 -05:00
interfaces Handle empty or all-blank PAGER setting more sanely in psql. 2016-12-07 12:19:56 -05:00
makefiles Provide NO_INSTALLCHECK option for pgxs. 2016-11-14 14:53:07 -08:00
pl Check that result tupdesc has exactly 1 column in return_next scalar case. 2016-11-15 16:48:19 -05:00
port Replace PostmasterRandom() with a stronger source, second attempt. 2016-12-05 13:42:59 +02:00
template Remove "sco" and "unixware" ports. 2016-10-11 11:26:04 -04:00
test Fix reporting of column typmods for multi-row VALUES constructs. 2016-12-08 11:40:02 -05:00
timezone More zic cleanup. 2016-11-06 10:45:58 -05:00
tools Implement table partitioning. 2016-12-07 13:17:55 -05:00
tutorial Update copyright for 2016 2016-01-02 13:33:40 -05:00
.gitignore
DEVELOPERS
Makefile Install TAP test infrastructure so it's available for extension testing. 2016-09-23 15:50:00 -04:00
Makefile.global.in Replace PostmasterRandom() with a stronger source, second attempt. 2016-12-05 13:42:59 +02:00
Makefile.shlib Remove "sco" and "unixware" ports. 2016-10-11 11:26:04 -04:00
bcc32.mak
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00
win32.mak