Re: Error message inconsistency

Mahendra Singh Thalor <[email protected]>
Newsgroups gmane.comp.db.postgresql.devel.general
Message-ID <CAKYtNAqRSkbV+scUerHu3vwaQHm1rhOPKth5GJcOUxT6ZmBf2Q@mail.gmail.com>
On Sat, 6 Jul 2019 at 09:53, Amit Kapila <[email protected]> wrote:
>
> On Mon, Jul 1, 2019 at 10:05 PM Alvaro Herrera <[email protected]>
wrote:
> >
> > Do we have an actual patch here?
> >
>
> We have a patch, but it needs some more work like finding similar
> places and change all of them at the same time and then change the
> tests to adapt the same.
>

Hi all,
Based on above discussion, I tried to find out all the places where we need
to change error for "not null constraint".  As Amit Kapila pointed out 1
place, I changed the error and adding modified patch.


*What does this patch? *
Before this patch, to display error of "not-null constraint", we were not
displaying relation name in some cases so attached patch is adding relation
name with the "not-null constraint" error in 2 places. I didn't changed out
files of test suite as we haven't finalized error messages.

I verified Robert's point of for partition tables also. With the error, we
are adding relation name of "child table" and i think, it is correct.

Please review attached patch and let me know feedback.

Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com
rationalize_constraint_error_messages_v2.patch (application/octet-stream, 1.5 KB)
commit 0d6619694bb4c20b9f006d5f71af61d5ddb4c2d7
Author: Mahendra Singh Thalor <[email protected]>
Date:   Mon Jan 6 18:14:40 2020 +0530

    Added table name in "not-null constrain" error

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 1c4394a..c683673 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -5007,8 +5007,9 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
 
 					ereport(ERROR,
 							(errcode(ERRCODE_NOT_NULL_VIOLATION),
-							 errmsg("column \"%s\" contains null values",
-									NameStr(attr->attname)),
+							 errmsg("column \"%s\" of relation \"%s\" contains null values",
+									NameStr(attr->attname),
+									RelationGetRelationName(oldrel)),
 							 errtablecol(oldrel, attn + 1)));
 				}
 			}
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 4181a7e..f787ead 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1957,8 +1957,9 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
 
 				ereport(ERROR,
 						(errcode(ERRCODE_NOT_NULL_VIOLATION),
-						 errmsg("null value in column \"%s\" violates not-null constraint",
-								NameStr(att->attname)),
+						 errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint",
+								NameStr(att->attname),
+								RelationGetRelationName(orig_rel)),
 						 val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
 						 errtablecol(orig_rel, attrChk)));
 			}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.