Fix CREATE TABLE LIKE INCLUDING GENERATED column order issue
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 9 Apr 2020 14:17:55 +0000 (16:17 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 9 Apr 2020 14:36:45 +0000 (16:36 +0200)
commite92e4a2b68fe877677278c1300db1780956c984e
tree9e651c181857cd6eeefa18a2c2a4f2768aacc7b7
parentc4f82a779d2676bfca1694a6f9b5499e6cc5f60f
Fix CREATE TABLE LIKE INCLUDING GENERATED column order issue

CREATE TABLE LIKE INCLUDING GENERATED would fail if a generated column
referred to a column with a higher attribute number.  This is because
the column mapping mechanism created the mapping incrementally as
columns are added.  This was sufficient for previous uses of that
mechanism (omitting dropped columns), and it also happened to work if
generated columns only referred to columns with lower attribute
numbers, but here it failed.

This fix is to build the attribute mapping in a separate loop before
processing the columns in detail.

Bug: #16342
Reported-by: Ethan Waldo <ewaldo@healthetechs.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
src/backend/parser/parse_utilcmd.c
src/test/regress/expected/create_table_like.out
src/test/regress/sql/create_table_like.sql