pgsql: Fix CREATE TABLE LIKE INCLUDING GENERATED column order issue

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix CREATE TABLE LIKE INCLUDING GENERATED column order issue
Date: 2020-04-09 14:42:09
Message-ID: E1jMYNd-00087S-63@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)healthetechs(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f06d583c5ad7a6a129d846103225448861f2df0d

Modified Files
--------------
src/backend/parser/parse_utilcmd.c | 25 ++++++++++++++++++---
src/test/regress/expected/create_table_like.out | 29 +++++++++++++------------
src/test/regress/sql/create_table_like.sql | 19 ++++++++--------
3 files changed, 47 insertions(+), 26 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2020-04-09 17:19:44 pgsql: Cosmetic improvements for default text search parser's ts_headli
Previous Message Fujii Masao 2020-04-09 13:39:36 pgsql: Exclude backup_manifest file that existed in database, from BASE