Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h0oZI-0001lW-TS for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Mar 2019 14:27:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h0oZH-0001XI-Jn for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Mar 2019 14:27:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h0oZH-0001U8-C2 for pgsql-bugs@lists.postgresql.org; Mon, 04 Mar 2019 14:27:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h0oZF-0006kV-Cz for pgsql-bugs@lists.postgresql.org; Mon, 04 Mar 2019 14:27:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x24ERheH032406; Mon, 4 Mar 2019 09:27:43 -0500 From: Tom Lane To: dirkjan@ochtman.nl cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15666: Seemingly incorrect error reporting/logging for violation of non-null constraint In-reply-to: <15666-ead8afdaca9e8cc4@postgresql.org> References: <15666-ead8afdaca9e8cc4@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 04 Mar 2019 09:55:31 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32404.1551709663.1@sss.pgh.pa.us> Date: Mon, 04 Mar 2019 09:27:43 -0500 Message-ID: <32405.1551709663@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > I'm modifying the data model for the application I work on, and in the > process of doing so, I'm seeing this error: > db | 2019-03-04 09:48:54.485 UTC [198] ERROR: null value in column > "accountid" violates not-null constraint > db | 2019-03-04 09:48:54.485 UTC [198] DETAIL: Failing row contains > (14, 138962.38, 0, null, 13). > db | 2019-03-04 09:48:54.485 UTC [198] STATEMENT: insert into > JournalEntryRecord (accountId, amount, journalEntryId, type, id) values ($1, > $2, $3, $4, $5) > This is very confusing to me because the tuple from the "Failing row" > message clearly has the `null` in fourth position, but the error message > reports that the column "accountid" (or "accountId" -- but I understand > column names are casefolded) is the problem, which should ostensibly be the > first value from the failing row tuple (if that tuple is ordered the same > way as the statement suggests). Well, maybe it isn't. That DETAIL line would report all the columns of the table, in their physical order. That doesn't necessarily have anything to do with the original INSERT, which --- if it has a column list, as this does --- can choose to target any subset of the columns in any order. We can't very well order the DETAIL to match the original INSERT, since it's entirely possible that the complaint is about a column not even mentioned in the INSERT. regards, tom lane