]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix reporting of column typmods for multi-row VALUES constructs.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 Dec 2016 17:01:14 +0000 (12:01 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 9 Dec 2016 17:01:14 +0000 (12:01 -0500)
commitc7a62135acfb951d2e6ca6c0cfc71ef4ed08f3bc
tree218939f962f22684a018fb8ec7af71708cc5e3c3
parent68e56eef655af48acc2d171fb724a803debe37f3
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.

We fixed this in HEAD by deriving the typmods during transformValuesClause
and storing them in the RTE, but that's not a feasible solution in the back
branches.  Instead, just use a brute-force approach of determining the
correct common typmod during expandRTE() and get_rte_attribute_type().
Simple testing says that that doesn't really cost much, at least not in
common cases where expandRTE() is only used once per query.  It turns out
that get_rte_attribute_type() is typically never used at all on VALUES
RTEs, so the inefficiency there is of no great concern.

Report: https://postgr.es/m/20161205143037.4377.60754@wrigleys.postgresql.org
Discussion: https://postgr.es/m/27429.1480968538@sss.pgh.pa.us
src/backend/parser/parse_relation.c
src/test/regress/expected/create_view.out
src/test/regress/sql/create_view.sql