pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column 3+ messages / 1 participants [nested] [flat]
* pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column @ 2026-10-06 04:15 Fujii Masao <fujii@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Fujii Masao @ 2026-10-06 04:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ADD PRIMARY KEY after dropping and re-adding a column Previously, dropping a NOT NULL column, adding a new column with the same name, and making it a primary key in a single ALTER TABLE command could fail with "primary key column ... is not marked NOT NULL". This happened because ALTER TABLE checked for an existing NOT NULL constraint before dropping the old column. Finding the constraint caused it to skip adding one for the new column, even though the old constraint would be removed with the old column. Defer this check until after column drops and additions have been executed, so that it examines the columns that will actually form the primary key. Add any required NOT NULL constraints before creating the primary-key index. Backpatch to v18, where this issue was introduced by commit a379061a22a. Reported-by: Ludvig Janiuk <ludvig.janiuk@proton.me> Author: Fujii Masao <masao.fujii@gmail.com> Co-authored-by: Manuel Reyes Bravo <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/0a9b4c44-cdff-4ec8-a8fb-b3a8b59e9ba9@proton.me Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/dd97e0c8e3823690653cd555090e01fafbb33a85 Modified Files -------------- src/backend/commands/tablecmds.c | 35 +++++++++++++++++++++---------- src/test/regress/expected/alter_table.out | 25 ++++++++++++++++++++++ src/test/regress/sql/alter_table.sql | 26 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column @ 2026-10-06 04:15 Fujii Masao <fujii@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Fujii Masao @ 2026-10-06 04:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ADD PRIMARY KEY after dropping and re-adding a column Previously, dropping a NOT NULL column, adding a new column with the same name, and making it a primary key in a single ALTER TABLE command could fail with "primary key column ... is not marked NOT NULL". This happened because ALTER TABLE checked for an existing NOT NULL constraint before dropping the old column. Finding the constraint caused it to skip adding one for the new column, even though the old constraint would be removed with the old column. Defer this check until after column drops and additions have been executed, so that it examines the columns that will actually form the primary key. Add any required NOT NULL constraints before creating the primary-key index. Backpatch to v18, where this issue was introduced by commit a379061a22a. Reported-by: Ludvig Janiuk <ludvig.janiuk@proton.me> Author: Fujii Masao <masao.fujii@gmail.com> Co-authored-by: Manuel Reyes Bravo <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/0a9b4c44-cdff-4ec8-a8fb-b3a8b59e9ba9@proton.me Backpatch-through: 18 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5e32454019b583bf0491ddb03afaeaaf99680ebc Modified Files -------------- src/backend/commands/tablecmds.c | 35 +++++++++++++++++++++---------- src/test/regress/expected/alter_table.out | 25 ++++++++++++++++++++++ src/test/regress/sql/alter_table.sql | 26 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column @ 2026-10-06 04:15 Fujii Masao <fujii@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Fujii Masao @ 2026-10-06 04:15 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ADD PRIMARY KEY after dropping and re-adding a column Previously, dropping a NOT NULL column, adding a new column with the same name, and making it a primary key in a single ALTER TABLE command could fail with "primary key column ... is not marked NOT NULL". This happened because ALTER TABLE checked for an existing NOT NULL constraint before dropping the old column. Finding the constraint caused it to skip adding one for the new column, even though the old constraint would be removed with the old column. Defer this check until after column drops and additions have been executed, so that it examines the columns that will actually form the primary key. Add any required NOT NULL constraints before creating the primary-key index. Backpatch to v18, where this issue was introduced by commit a379061a22a. Reported-by: Ludvig Janiuk <ludvig.janiuk@proton.me> Author: Fujii Masao <masao.fujii@gmail.com> Co-authored-by: Manuel Reyes Bravo <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/0a9b4c44-cdff-4ec8-a8fb-b3a8b59e9ba9@proton.me Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5659e549adeb9de1a89efa181b032044ada64b1f Modified Files -------------- src/backend/commands/tablecmds.c | 35 +++++++++++++++++++++---------- src/test/regress/expected/alter_table.out | 25 ++++++++++++++++++++++ src/test/regress/sql/alter_table.sql | 26 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 11 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-10-06 04:15 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-06 04:15 pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column Fujii Masao <fujii@postgresql.org> 2026-10-06 04:15 pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column Fujii Masao <fujii@postgresql.org> 2026-10-06 04:15 pgsql: Fix ADD PRIMARY KEY after dropping and re-adding a column Fujii Masao <fujii@postgresql.org>
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