mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Fix application of identity values in some cases
Investigation of 2d2d06b7e2
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>
This commit is contained in:
@ -472,6 +472,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
|
||||
|
Reference in New Issue
Block a user