pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
csv copy error
5+ messages / 4 participants
[nested] [flat]

* csv copy error
@ 2021-12-29 21:08  ourdiaspora <ourdiaspora@protonmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: ourdiaspora @ 2021-12-29 21:08 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Readers,

Please could anyone help with the following error produced:

"
ERROR:  invalid input syntax for integer: "1,m "
CONTEXT:  COPY exampletable, line 1, column examplenumber: "1,m "

The database commands:

"
CREATE TABLE exampletable (examplenumber smallint,
exampletitle varchar(500)
);
"

"
 \copy exampletable from '/local/path/to/examplefile.csv';
"

CSV file contents:

"
1,m
2,m
9,t
"






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: csv copy error
@ 2021-12-29 21:15  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: ourdiaspora <ourdiaspora@protonmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Adrian Klaver @ 2021-12-29 21:15 UTC (permalink / raw)
  To: ourdiaspora <ourdiaspora@protonmail.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On 12/29/21 13:08, ourdiaspora wrote:
> Readers,
> 
> Please could anyone help with the following error produced:
> 
> "
> ERROR:  invalid input syntax for integer: "1,m "
> CONTEXT:  COPY exampletable, line 1, column examplenumber: "1,m "
> 
> The database commands:
> 
> "
> CREATE TABLE exampletable (examplenumber smallint,
> exampletitle varchar(500)
> );
> "
> 
> "
>   \copy exampletable from '/local/path/to/examplefile.csv';
> "

\copy exampletable from '/local/path/to/examplefile.csv with csv';

> 
> CSV file contents:
> 
> "
> 1,m
> 2,m
> 9,t
> "
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: csv copy error
@ 2021-12-29 21:46  David G. Johnston <david.g.johnston@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 5+ messages in thread

From: David G. Johnston @ 2021-12-29 21:46 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: ourdiaspora <ourdiaspora@protonmail.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Wednesday, December 29, 2021, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:

> On 12/29/21 13:08, ourdiaspora wrote:
>
>>
>> "
>>   \copy exampletable from '/local/path/to/examplefile.csv';
>> "
>>
>
> \copy exampletable from '/local/path/to/examplefile.csv with csv';
>
>
Right idea though that won’t execute for three reasons (bad quoting,
missing parentheses, missing field type for the value csv).  The main issue
is the OP is accepting all defaults but the file format is not in the
default format.  Either the format needs to be changed or the OP needs to
specify a combination of options that describes the file format.
Specifying the csv format I think is a valid solution though there are
others.  The documentation describes the options, syntax, and effects
sufficiently so I will not belabor the details.

David J.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: csv copy error
@ 2021-12-30 07:30  Guillaume Lelarge <guillaume@lelarge.info>
  parent: ourdiaspora <ourdiaspora@protonmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Guillaume Lelarge @ 2021-12-30 07:30 UTC (permalink / raw)
  To: ourdiaspora <ourdiaspora@protonmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi,

Le mer. 29 déc. 2021 à 22:08, ourdiaspora <ourdiaspora@protonmail.com> a
écrit :

> Readers,
>
> Please could anyone help with the following error produced:
>
> "
> ERROR:  invalid input syntax for integer: "1,m "
> CONTEXT:  COPY exampletable, line 1, column examplenumber: "1,m "
>
> The database commands:
>
> "
> CREATE TABLE exampletable (examplenumber smallint,
> exampletitle varchar(500)
> );
> "
>
> "
>  \copy exampletable from '/local/path/to/examplefile.csv';
> "
>
> CSV file contents:
>
> "
> 1,m
> 2,m
> 9,t
> "
>
>
You should tell the CSV command you're using a CSV file. By default, COPY
thinks it's a TSV file.


-- 
Guillaume.

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: csv copy error
@ 2021-12-31 10:03  ourdiaspora <ourdiaspora@protonmail.com>
  parent: Guillaume Lelarge <guillaume@lelarge.info>
  0 siblings, 0 replies; 5+ messages in thread

From: ourdiaspora @ 2021-12-31 10:03 UTC (permalink / raw)
  To: Guillaume Lelarge <guillaume@lelarge.info>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>


On Thursday, December 30th, 2021 at 7:30 AM, Guillaume Lelarge <guillaume@lelarge.info> wrote:

> Hi,
>
> Le mer. 29 déc. 2021 à 22:08, ourdiaspora <ourdiaspora@protonmail.com> a écrit :
>
> >
> > \copy exampletable from '/local/path/to/examplefile.csv';
> >
>
> You should tell the CSV command you're using a CSV file. By default, COPY thinks it's a TSV file.
>

Problem solved with:

"
...file.csv' with csv;
"

Thanks to all.






^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2021-12-31 10:03 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-12-29 21:08 csv copy error ourdiaspora <ourdiaspora@protonmail.com>
2021-12-29 21:15 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-12-29 21:46   ` David G. Johnston <david.g.johnston@gmail.com>
2021-12-30 07:30 ` Guillaume Lelarge <guillaume@lelarge.info>
2021-12-31 10:03   ` ourdiaspora <ourdiaspora@protonmail.com>

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