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.paqu...@gmail.com> Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1597948c962a1407c01fc492c44917c097efa92e 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(-)