Re: Is it possible to set end-of-data marker for COPY statement.

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Junfeng Yang <yjerome(at)vmware(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Is it possible to set end-of-data marker for COPY statement.
Date: 2020-09-01 17:25:50
Message-ID: 20200901172550.GY13613@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Sep 1, 2020 at 06:14:45AM +0000, Junfeng Yang wrote:
> Hi hackers,
>
> As described in the doc https://www.postgresql.org/docs/current/sql-copy.html,
> the TEXT format recognizes
> backslash-period (\.) as end-of-data marker.
>
> The example below will raise an error for the line contains `\.`.
>
> CREATE TABLE test (
> id int,
> name text,
> dep text
> )
>
> Data in file "/tmp/data".
>
> 122,as\.d,adad
> 133,sa dad,adadad
>
> Then execute
>
> copy test from '/tmp/data' DELIMITER ',';
>
> An end-of-copy marker corrupt error will be raised.
>
> This requires users to escape the end-of-data marker manually in their data.
> Why we don't have a mechanism to define other characters as end-of-data marker?
> Or there are other ways to avoid escape the end-of-data in data?

So, you are using comma as the delimiter, but have \. (backslash-period)
as a data value. You need to double-up backslashes in your input data,
no matter what is after the backslash. You just happen to hit backslash
period, but other things like \N could cause problems --- literal
backslashes have to be doubled.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EnterpriseDB https://enterprisedb.com

The usefulness of a cup is in its emptiness, Bruce Lee

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-09-01 18:01:06 Re: Is it possible to set end-of-data marker for COPY statement.
Previous Message Bruce Momjian 2020-09-01 17:23:00 Re: Is it possible to set end-of-data marker for COPY statement.

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-09-01 18:01:06 Re: Is it possible to set end-of-data marker for COPY statement.
Previous Message Bruce Momjian 2020-09-01 17:23:00 Re: Is it possible to set end-of-data marker for COPY statement.