Re: COPY options

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: "Andrei M(dot) Eichler" <andrei(dot)eichler(at)unicheck(dot)com(dot)br>
Cc: "pgsql-docs(at)postgresql(dot)org" <pgsql-docs(at)postgresql(dot)org>
Subject: Re: COPY options
Date: 2016-04-29 15:53:57
Message-ID: CACjxUsMcsVT3N_znoWem2BtFvHtKtnNFKcJauVT4krtpjujgAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Fri, Apr 29, 2016 at 10:31 AM, Andrei M. Eichler
<andrei(dot)eichler(at)unicheck(dot)com(dot)br> wrote:

> Following the documentation, I wrote this COPY FROM command:
>
> COPY test_copy FROM '/mnt/disk1/files/test_file.csv' with csv header
> delimiter ';' force_null date_column, date_column2, date_column3,
> date_column4, date_column5 encoding 'latin1';

The syntax synopsis in the current docs requires parentheses around
any options. I was a little surprised that you got it to work at
all without them; but then remembered there is older (deprecated
and undocumented) syntax that was not ripped out to avoid breaking
code which was working before the syntax change in 9.0. To do this
per the current documentation (which I would strongly recommend
over the old, undocumented, deprecated syntax), try this:

COPY test_copy FROM '/mnt/disk1/files/test_file.csv' with (
format csv,
header true,
delimiter ';',
force_null (date_column, date_column2, date_column3, date_column4,
date_column5),
encoding 'latin1'
);

This new syntax was adopted to make it easier to add new options,
and to avoid having to define new keywords or reserved words to do
so.

It's not really a question of whether we should go back to
documenting the deprecated syntax, but whether (and when) support
for it should finally be ripped out. It was last documented in 8.4.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2016-04-29 16:03:44 Re: COPY options
Previous Message Tom Lane 2016-04-29 15:50:38 Re: COPY options