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: 0001-Adjust-the-error-message-to-reflect-the-inheritance-.patch
Description: Binary data

Reply via email to