postgresql/src/include/catalog
Tom Lane a3c7a993d5 Make INSERT-from-multiple-VALUES-rows handle targetlist indirection better.
Previously, if an INSERT with multiple rows of VALUES had indirection
(array subscripting or field selection) in its target-columns list, the
parser handled that by applying transformAssignedExpr() to each element
of each VALUES row independently.  This led to having ArrayRef assignment
nodes or FieldStore nodes in each row of the VALUES RTE.  That works for
simple cases, but in bug #14265 Nuri Boardman points out that it fails
if there are multiple assignments to elements/fields of the same target
column.  For such cases to work, rewriteTargetListIU() has to nest the
ArrayRefs or FieldStores together to produce a single expression to be
assigned to the column.  But it failed to find them in the top-level
targetlist and issued an error about "multiple assignments to same column".

We could possibly fix this by teaching the rewriter to apply
rewriteTargetListIU to each VALUES row separately, but that would be messy
(it would change the output rowtype of the VALUES RTE, for example) and
inefficient.  Instead, let's fix the parser so that the VALUES RTE outputs
are just the user-specified values, cast to the right type if necessary,
and then the ArrayRefs or FieldStores are applied in the top-level
targetlist to Vars representing the RTE's outputs.  This is the same
parsetree representation already used for similar cases with INSERT/SELECT
syntax, so it allows simplifications in ruleutils.c, which no longer needs
to treat INSERT-from-multiple-VALUES as its own special case.

This implementation works by applying transformAssignedExpr to the VALUES
entries as before, and then stripping off any ArrayRefs or FieldStores it
adds.  With lots of VALUES rows it would be noticeably more efficient to
not add those nodes in the first place.  But that's just an optimization
not a bug fix, and there doesn't seem to be any good way to do it without
significant refactoring.  (A non-invasive answer would be to apply
transformAssignedExpr + stripping to just the first VALUES row, and then
just forcibly cast remaining rows to the same data types exposed in the
first row.  But this way would lead to different, not-INSERT-specific
errors being reported in casting failure cases, so it doesn't seem very
nice.)  So leave that for later; this patch at least isn't making the
per-row parsing work worse, and it does make the finished parsetree
smaller, saving rewriter and planner work.

Catversion bump because stored rules containing such INSERTs would need
to change.  Because of that, no back-patch, even though this is a very
long-standing bug.

Report: <20160727005725.7438.26021@wrigleys.postgresql.org>
Discussion: <9578.1469645245@sss.pgh.pa.us>
2016-08-03 16:37:03 -04:00
..
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
binary_upgrade.h Fix pg_upgrade to not fail when new-cluster TOAST rules differ from old. 2016-05-06 22:05:56 -04:00
catalog.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
catversion.h Make INSERT-from-multiple-VALUES-rows handle targetlist indirection better. 2016-08-03 16:37:03 -04:00
dependency.h Support ALTER THING .. DEPENDS ON EXTENSION 2016-04-05 18:38:54 -03:00
duplicate_oids pgindent run for 9.4 2014-05-06 12:12:18 -04:00
genbki.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
heap.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
index.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
indexing.h Add new catalog called pg_init_privs 2016-04-06 21:45:32 -04:00
namespace.h Improve the situation for parallel query versus temp relations. 2016-06-09 20:16:11 -04:00
objectaccess.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
objectaddress.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
opfam_internal.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_aggregate.h Fix type-safety problem with parallel aggregate serial/deserialization. 2016-06-22 16:52:41 -04:00
pg_am.h Support CREATE ACCESS METHOD 2016-03-23 23:01:35 -03:00
pg_amop.h Introduce SP-GiST operator class over box. 2016-03-30 18:42:36 +03:00
pg_amproc.h Introduce SP-GiST operator class over box. 2016-03-30 18:42:36 +03:00
pg_attrdef.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_attribute.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_auth_members.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_authid.h Create default roles 2016-04-08 16:56:27 -04:00
pg_cast.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_class.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
pg_collation.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_collation_fn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_constraint.h Revert CREATE INDEX ... INCLUDING ... 2016-04-08 21:52:13 +03:00
pg_constraint_fn.h Revert CREATE INDEX ... INCLUDING ... 2016-04-08 21:52:13 +03:00
pg_control.h Advance PG_CONTROL_VERSION. 2016-07-16 12:49:14 -04:00
pg_conversion.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_conversion_fn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_database.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_db_role_setting.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_default_acl.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_depend.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_description.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_enum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_event_trigger.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_extension.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_foreign_data_wrapper.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_foreign_server.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_foreign_table.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_index.h Revert CREATE INDEX ... INCLUDING ... 2016-04-08 21:52:13 +03:00
pg_inherits.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_inherits_fn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_init_privs.h Add new catalog called pg_init_privs 2016-04-06 21:45:32 -04:00
pg_language.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_largeobject.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_largeobject_metadata.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_namespace.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_opclass.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
pg_operator.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
pg_operator_fn.h Fix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator. 2016-03-25 12:33:16 -04:00
pg_opfamily.h Introduce SP-GiST operator class over box. 2016-03-30 18:42:36 +03:00
pg_pltemplate.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_policy.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_proc.h Remove unused arguments from pg_replication_origin_xact_reset function. 2016-08-02 02:43:17 +09:00
pg_proc_fn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_range.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_replication_origin.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_rewrite.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_seclabel.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_shdepend.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_shdescription.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_shseclabel.h Make pg_shseclabel available in early backend startup 2016-01-05 14:50:53 -03:00
pg_statistic.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_tablespace.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_transform.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_trigger.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_ts_config.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_ts_config_map.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_ts_dict.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_ts_parser.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_ts_template.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_type.h pgindent run for 9.6 2016-06-09 18:02:36 -04:00
pg_type_fn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_user_mapping.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage_xlog.h pg_visibility: Add pg_truncate_visibility_map function. 2016-06-17 17:37:30 -04:00
toasting.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
unused_oids Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00