From: Peter Eisentraut <peter_e@gmx.net>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix application of identity values in some cases
Date: Fri, 02 Feb 2018 20:07:10 +0000
Message-ID: <E1ehhc6-0001sh-EP@gemulon.postgresql.org> (raw)
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.paquier@gmail.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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: peter_e@gmx.net
Subject: Re: pgsql: Fix application of identity values in some cases
In-Reply-To: <E1ehhc6-0001sh-EP@gemulon.postgresql.org>
References: <E1ehhc6-0001sh-EP@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox