42P16 error when dropping and adding column

From: Ludvig Janiuk <ludvig(dot)janiuk(at)proton(dot)me>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: 42P16 error when dropping and adding column
Date: 2026-09-17 09:51:54
Message-ID: 0a9b4c44-cdff-4ec8-a8fb-b3a8b59e9ba9@proton.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello, it seems that between pqsl 17 and 18, the behavior of the
following reproducer has changed:

====
CREATE TABLE reproducer(id int NOT NULL); ALTER TABLE reproducer DROP
COLUMN "id", ADD COLUMN "id" int, ADD PRIMARY KEY("id");
====

Expected output (this is the case on psql 16 and 17):

====
CREATE TABLE
ALTER TABLE
====

Actual output (on psql (PostgreSQL) 18.6 (Ubuntu 18.6-0ubuntu0.26.04.1)):

====
CREATE TABLE
ERROR:  42P16: primary key column "id" is not marked NOT NULL
LOCATION:  index_check_primary_key, index.c:266
====

I could not find anything direcly related in the change notes
(https://www.postgresql.org/docs/release/18.0/) There were a few lines
related to NULL, but with my knowledge I could not be sure if they were
relevant.

I hope you can accept my bug report, or let me know the reason why if
this is correct behavior.

Best regards,

--
//Ludvig Janiuk

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-09-17 14:22:11 Re: 42P16 error when dropping and adding column
Previous Message PG Bug reporting form 2026-09-17 08:49:01 BUG #19692: Generic partition-pruning plan delays statement_timeout cancellation