pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Patrick van Coeverden <patrick.van.coeverden@topicus.nl>
To: pgsql-bugs@postgresql.org
Subject: Line number in error message is incorrect when loading a CSV-file with multi-line records.
Date: Wed, 6 Sep 2017 20:24:58 +0200
Message-ID: <08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

csv_with_multiline_records.csv (text/csv, 446B) download "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"
line_nr_test.sql (application/sql, 392B) download

Message-ID: <08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl>
Permalink:  ../08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl/
Also on:    postgresql.org/message-id/08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: patrick.van.coeverden@topicus.nl
  Subject: Re: Line number in error message is incorrect when loading a CSV-file with multi-line records.
  In-Reply-To: <08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl>
  References: <08f86723-0672-eecb-900a-930960d7e6ec@topicus.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox