From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Andrew Kerber <andrew.kerber@gmail.com>
To: raf@raf.org
Cc: pgsql-general@lists.postgresql.org
Subject: Re:
Date: Tue, 2 Jul 2019 16:14:28 -0700
Message-ID: <1c5d14ca-c519-bcb3-a912-9d1d77022c73@aklaver.com> (raw)
In-Reply-To: <CAJvnOJY0qhDznyAp_pO-ihe-vjrmc=qhP56V9cxZA5FDMQ=ZFQ@mail.gmail.com>
References: <CAA2eZXx43admgo7gj_zHS-_AUqfB6yx1Qdhjvr47YjQH95-ChQ@mail.gmail.com>
<45312c734ff4177639b309940be4017d91f4a38b.camel@cybertec.at>
<20190702230427.sgmhd6wwf2j5mima@raf.org>
<CAJvnOJY0qhDznyAp_pO-ihe-vjrmc=qhP56V9cxZA5FDMQ=ZFQ@mail.gmail.com>
On 7/2/19 4:08 PM, Andrew Kerber wrote:
> Yes, CSV stands for comma separated variable length. This means that
CSV = Comma Separated Values
> the fields in each row should be separated by commas, with a carriage
> return at the end of each record. You have a file using | separators,
> which mean it is not csv.
That is not strictly true:
https://en.wikipedia.org/wiki/Comma-separated_values
And is definitely not true for this context, using Postgres COPY:
https://www.postgresql.org/docs/9.6/sql-copy.html
"CSV Format
This format option is used for importing and exporting the Comma
Separated Value (CSV) file format used by many other programs, such as
spreadsheets. Instead of the escaping rules used by PostgreSQL's
standard text format, it produces and recognizes the common CSV escaping
mechanism.
The values in each record are separated by the DELIMITER character. If
the value contains the delimiter character, the QUOTE character, the
NULL string, a carriage return, or line feed character, then the whole
value is prefixed and suffixed by the QUOTE character, and any
occurrence within the value of a QUOTE character or the ESCAPE character
is preceded by the escape character. You can also use FORCE_QUOTE to
force quotes when outputting non-NULL values in specific columns.
...
"
You do have to specify the delimiter if it is not the default comma. In
the OP's case the delimiter would need to be set to '|'.
>
> On Tue, Jul 2, 2019 at 6:04 PM <raf@raf.org <mailto:raf@raf.org>> wrote:
>
> Laurenz Albe wrote:
>
> > On Tue, 2019-07-02 at 13:09 +0530, Prakash Ramakrishnan wrote:
> > > We are getting below error while during import the csv file
> please do the needful.
> >
> > I'd say the needful thing here is for you to read the
> documentation...
> >
> > > -bash-4.2$ more ckr_sto.csv
> > > 4937880 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128790679 | |
> | |
> > > 4939355 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128639345 | |
> | |
> > > 4939744 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128684510 | |
> | |
> > > 4939750 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128683100 | |
> | |
> > > 4936360 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128567527 | |
> | |
> > > 4940308 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128781329 | |
> | |
> > > 4938006 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 4000128912554 | |
> | |
> > > 4937457 | 12 | 2015-01-05 | | 2015-01-05
> 05:51:47 | | | 5000128426574 | |
> | |
> > >
> > > error
> > > ----------
> > > postgres=# \copy ckr_sto from /data/ckr_sto.csv CSV HEADER;
> > > ERROR: invalid input syntax for integer: " 4939355 | 12 |
> 2015-01-05 | | 2015-01-05 05:51:47 | | |
> 5000128639345 | | | | "
> > > CONTEXT: COPY ckr_sto, line 2, column pod_id: " 4939355 |
> 12 | 2015-01-05 | | 2015-01-05 05:51:47 | |
> | 500012863934..."
> >
> > >From the documentation of COPY:
> >
> > DELIMITER
> >
> > Specifies the character that separates columns within each
> row (line) of the file.
> > The default is a tab character in text format, a comma in CSV
> format.
> > This must be a single one-byte character. This option is not
> allowed when using binary format.
> >
> > Yours,
> > Laurenz Albe
> > --
> > Cybertec | https://www.cybertec-postgresql.com
>
> in other words, ckr_sto.csv is not a csv file.
> it just has .csv at the end of its name.
> that's why psql tried to interpret the entire
> line as the first column: there were no commas.
>
> its contents should look something like:
>
> 4937880,12,2015-01-05,,2015-01-05 05:51:47,,,5000128790679,,,,
> 4939355,12,2015-01-05,,2015-01-05 05:51:47,,,5000128639345,,,,
> 4939744,12,2015-01-05,,2015-01-05 05:51:47,,,5000128684510,,,,
> 4939750,12,2015-01-05,,2015-01-05 05:51:47,,,5000128683100,,,,
> 4936360,12,2015-01-05,,2015-01-05 05:51:47,,,5000128567527,,,,
> 4940308,12,2015-01-05,,2015-01-05 05:51:47,,,5000128781329,,,,
> 4938006,12,2015-01-05,,2015-01-05 05:51:47,,,4000128912554,,,,
> 4937457,12,2015-01-05,,2015-01-05 05:51:47,,,5000128426574,,,,
>
>
>
>
>
> --
> Andrew W. Kerber
>
> 'If at first you dont succeed, dont take up skydiving.'
--
Adrian Klaver
adrian.klaver@aklaver.com
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-general@postgresql.org
Cc: adrian.klaver@aklaver.com, andrew.kerber@gmail.com, raf@raf.org
Subject: Re:
In-Reply-To: <1c5d14ca-c519-bcb3-a912-9d1d77022c73@aklaver.com>
References: <CAA2eZXx43admgo7gj_zHS-_AUqfB6yx1Qdhjvr47YjQH95-ChQ@mail.gmail.com> <45312c734ff4177639b309940be4017d91f4a38b.camel@cybertec.at> <20190702230427.sgmhd6wwf2j5mima@raf.org> <CAJvnOJY0qhDznyAp_pO-ihe-vjrmc=qhP56V9cxZA5FDMQ=ZFQ@mail.gmail.com> <1c5d14ca-c519-bcb3-a912-9d1d77022c73@aklaver.com>
* 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