pgsql: Fix application of identity values in some cases

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix application of identity values in some cases
Date: 2018-02-02 20:07:10
Message-ID: E1ehhc6-0001sh-EP@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix application of identity values in some cases

Investigation of 2d2d06b7e27e3177d5bef0061801c75946871db3 revealed that
identity values were not applied in some further cases, including
logical replication subscribers, VALUES RTEs, and ALTER TABLE ... ADD
COLUMN. To fix all that, apply the identity column expression in
build_column_default() instead of repeating the same logic at each call
site.

For ALTER TABLE ... ADD COLUMN ... IDENTITY, the previous coding
completely ignored that existing rows for the new column should have
values filled in from the identity sequence. The coding using
build_column_default() fails for this because the sequence ownership
isn't registered until after ALTER TABLE, and we can't do it before
because we don't have the column in the catalog yet. So we specially
remember in ColumnDef the sequence name that we decided on and build a
custom NextValueExpr using that.

Reviewed-by: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/533c5d8bddf0feb1785b3da17c0d17feeaac76d8

Modified Files
--------------
src/backend/commands/copy.c | 16 ++--------------
src/backend/commands/tablecmds.c | 16 +++++++++++++++-
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/equalfuncs.c | 1 +
src/backend/nodes/outfuncs.c | 1 +
src/backend/parser/parse_utilcmd.c | 8 ++++++++
src/backend/rewrite/rewriteHandler.c | 22 +++++++++++-----------
src/include/nodes/parsenodes.h | 2 ++
src/test/regress/expected/identity.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/identity.sql | 19 +++++++++++++++++++
src/test/subscription/t/008_diff_schema.pl | 18 ++++++++++++++----
11 files changed, 102 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-02-02 22:10:51 pgsql: First-draft release notes for 10.2.
Previous Message Robert Haas 2018-02-02 18:37:11 pgsql: Support parallel btree index builds.