Adjust error message to reflect the inheritance relationship

Started by Tender Wang7 months ago2 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
2 days ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Tender Wang
tndrwang@gmail.com

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

Attachments:

t139596_1
0001-Adjust-the-error-message-to-reflect-the-inheritance-.patchapplication/octet-stream; name=0001-Adjust-the-error-message-to-reflect-the-inheritance-.patchDownload+2-3
#2Alvaro Herrera
alvherre@kurilemu.de
In reply to: Tender Wang (#1)
Re: Adjust error message to reflect the inheritance relationship

On 2026-May-09, Tender Wang wrote:

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?

Makes sense, pushed, no backpatch. Thanks

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Are you not unsure you want to delete Firefox?
[Not unsure] [Not not unsure] [Cancel]
http://smylers.hates-software.com/2008/01/03/566e45b2.html