aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_utilcmd.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2018-02-02 14:20:50 -0500
committerPeter Eisentraut <peter_e@gmx.net>2018-02-02 14:39:10 -0500
commit533c5d8bddf0feb1785b3da17c0d17feeaac76d8 (patch)
tree00a87043248bc7a604e5c0a185a04489288cd8ed /src/backend/parser/parse_utilcmd.c
parent9da0cc35284bdbe8d442d732963303ff0e0a40bc (diff)
downloadpostgresql-533c5d8bddf0feb1785b3da17c0d17feeaac76d8.tar.gz
postgresql-533c5d8bddf0feb1785b3da17c0d17feeaac76d8.zip
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>
Diffstat (limited to 'src/backend/parser/parse_utilcmd.c')
-rw-r--r--src/backend/parser/parse_utilcmd.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 1d35815fcfe..d415d7180f2 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -473,6 +473,14 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
cxt->blist = lappend(cxt->blist, seqstmt);
/*
+ * Store the identity sequence name that we decided on. ALTER TABLE
+ * ... ADD COLUMN ... IDENTITY needs this so that it can fill the new
+ * column with values from the sequence, while the association of the
+ * sequence with the table is not set until after the ALTER TABLE.
+ */
+ column->identitySequence = seqstmt->sequence;
+
+ /*
* Build an ALTER SEQUENCE ... OWNED BY command to mark the sequence as
* owned by this column, and add it to the list of things to be done after
* this CREATE/ALTER TABLE.