Skip site navigation (1) Skip section navigation (2)

NOT NULL violation and error-message

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: NOT NULL violation and error-message
Date: 2010-01-08 21:55:00
Message-ID: 201001082255.00602.andreak@officenet.no (view raw or flat)
Thread:
Lists: pgsql-hackers
Hi all, when trying to insert/update a NOT NULL column with a null-values (in this case the "created"-column), we get this error:

ERROR: null value in column "created" violates not-null constraint

Using JDBC this error-message is what appears in the SQLException.getMessage() which makes it impossible to tell which table the NOT_NULL_VIOLATION happened in. This can be a real pain as this might happen upon transaction-commit using OR-tools like Hibernate. The transaction might involve updating several tables with the same column-name rendering it impossible to extract what the error really is from the error-message. Is there a way to prefix the column-name in the error-message with table-name and maybe also schema-name? The message would then instead read something like:

ERROR: null value in column "public"."mytable"."created" violates not-null constraint

Oracle does this btw...

-- 
Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Senior Software Developer / CTO
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 TrollÄsen          | somebody else doing it wrong, without       |
NORWAY                  | comment.                                    |
                        |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

Responses

pgsql-hackers by date

Next:From: Michael MeskesDate: 2010-01-08 21:57:36
Subject: Re: pgsql: Also update ChangerLog file.
Previous:From: Merlin MoncureDate: 2010-01-08 21:23:11
Subject: Re: Listen / Notify - what to do when the queue is full

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group