Fix application of identity values in some cases
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 2 Feb 2018 19:20:50 +0000 (14:20 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 2 Feb 2018 20:06:52 +0000 (15:06 -0500)
commit1597948c962a1407c01fc492c44917c097efa92e
treee3e4973b4894c4d0b0aeba71414222d20087b5c8
parentb94988fad56167915231d3d2b275c471914301fe
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>
src/backend/commands/copy.c
src/backend/commands/tablecmds.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/parser/parse_utilcmd.c
src/backend/rewrite/rewriteHandler.c
src/include/nodes/parsenodes.h
src/test/regress/expected/identity.out
src/test/regress/sql/identity.sql
src/test/subscription/t/008_diff_schema.pl