Adjust error message to reflect the inheritance relationship

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: Adjust error message to reflect the inheritance relationship
Date: 2026-05-09 02:51:44
Message-ID: CAHewXNkxN0nZpQZBAJ=wNH-dOyo-9LkGPT0dbQhrLS=2KHG6UA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

postgres=# CREATE TABLE t0(c0 boolean );
CREATE TABLE t3(c0 boolean ) INHERITS(t0);
ALTER TABLE ONLY t0 ADD CONSTRAINT Z PRIMARY KEY(c0);
CREATE TABLE
NOTICE: merging column "c0" with inherited definition
CREATE TABLE
ERROR: column "c0" of table "t3" is not marked NOT NULL

The above error was found in my recent test on HEAD.
At first glance, the error message appears incorrect because we only
want to add PK to the parent table t0.
I go back to see the code, and find the comments below around
ATPrepAddPrimaryKey()
...
* For the case where we're asked not to recurse, we verify that a not-null
* constraint exists on each column of each (direct) child table, throwing an
* error if not. Not throwing an error would also work, because a not-null
* constraint would be created anyway, but it'd cause a silent scan of the
* child table to verify absence of nulls.
...
Yeah, the error message is expected.
I want to add the word " child " to the error message to reflect the
inheritance relationship.
I searched the `tablecmds.c` file using the keyword "child table" and
received a similar error message, as shown below.

"column \"%s\" in child table \"%s\" must be marked NOT NULL"

”is not marked NOT NULL" works for me. So I only replaced the original
error message "of" with "in child".
The new error message will be:
ERROR: column "c0" in child table "t3" is not marked NOT NULL

Any thoughts?
--
Thanks,
Tender Wang

Attachment Content-Type Size
0001-Adjust-the-error-message-to-reflect-the-inheritance-.patch application/octet-stream 1.8 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2026-05-09 02:52:25 Re: Fix wrong error message from pg_get_tablespace_ddl()
Previous Message Lakshmi N 2026-05-09 02:47:58 avoid false dropped replication slot log messages