Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpf7d-0004My-0X for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Sep 2017 18:32:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dpf7c-0005wP-JN for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Sep 2017 18:32:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dpf0g-0003Gd-Ur for pgsql-bugs@postgresql.org; Wed, 06 Sep 2017 18:25:11 +0000 Received: from exchange.topicus.nl ([195.35.227.206]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dpf0Z-0002WJ-UX for pgsql-bugs@postgresql.org; Wed, 06 Sep 2017 18:25:09 +0000 Received: from [192.168.178.24] (84.245.50.104) by EXCH-HC02.topicus.local (192.168.3.210) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 6 Sep 2017 20:24:58 +0200 To: From: Patrick van Coeverden Subject: Line number in error message is incorrect when loading a CSV-file with multi-line records. Message-ID: <08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl> Date: Wed, 6 Sep 2017 20:24:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BE0FD57DCFD770BCE67C6914" X-Originating-IP: [84.245.50.104] List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --------------BE0FD57DCFD770BCE67C6914 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Hello, I am importing CSV files into a Postgres database with the COPY statement. Some of the CSV files do have records that span over multiple lines. These records are surrounded by double-quotes. This imports fine when there are no errors. However, when an error is thrown because of an unique constraint, the line number in the error message is off. I have attached an example CSV and SQL file. When executing the attached SQL-file (change the location of the CSV), the following error message appears: ERROR: duplicate key value violates unique constraint "import_test_pkey" DETAIL: Key (id)=(3) already exists. CONTEXT: COPY import_test, line 13 However, the error in the CSV is located at line 23 (Or the 4th record) Postgres version: "PostgreSQL 9.6.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit" OS: Linux Mint Thanks, Patrick van Coeverden --------------BE0FD57DCFD770BCE67C6914 Content-Type: text/csv; name="csv_with_multiline_records.csv" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="csv_with_multiline_records.csv" "id";"textfield" 1;"Record Line 1 Record 1 line 2 Record 1 line 3 Record 1 Line 4 Record 1 line 5 Record 1 line 6 Record 1 line 7 Record 1 line 8 Record 1 line 9" 2;"Record 2 Line 1 Record 2 line 2 Record 2 line 3 Record 2 Line 4 Record 2 line 5 Record 2 line 6 Record 2 line 7 Record 2 line 8 Record 2 line 9" 3;"Record 3 Line 1 Record 3 line 2 Record 3 line 3" 3;"Duplicate Record 3 Line 1 Duplicate Record 3 line 2 Duplicate Record 3 line 3" --------------BE0FD57DCFD770BCE67C6914 Content-Type: application/sql; name="line_nr_test.sql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="line_nr_test.sql" U0VUIFNFQVJDSF9QQVRIIFRPIHB1YmxpYzsKRFJPUCBUQUJMRSBJRiBFWElT VFMgaW1wb3J0X3Rlc3Q7CkNSRUFURSBUQUJMRSBpbXBvcnRfdGVzdAooCiAg aWQgQklHSU5UIE5PVCBOVUxMLAogIHRleHRmaWVsZCB0ZXh0LAogIENPTlNU UkFJTlQgaW1wb3J0X3Rlc3RfcGtleSBQUklNQVJZIEtFWSAoaWQpCik7CkNP UFkgaW1wb3J0X3Rlc3QgKGlkLCB0ZXh0ZmllbGQpIEZST00gJy9ob21lL3Bh dHJpY2svRGVza3RvcC9jc3Zfd2l0aF9tdWx0aWxpbmVfcmVjb3Jkcy5jc3Yn ICBERUxJTUlURVIgJzsnIENTViBIRUFERVI7ICAtLWNoYW5nZSB0aGUgbG9j YXRpb24gb2YgY3N2X3dpdGhfbXVsdGlsaW5lX3JlY29yZHMuY3N2IHRvIHlv dXJzClNFTEVDVCAqIEZST00gaW1wb3J0X3Rlc3Q7Cgo= --------------BE0FD57DCFD770BCE67C6914 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------BE0FD57DCFD770BCE67C6914--