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

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Junfeng Yang <yjerome(at)vmware(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Is it possible to set end-of-data marker for COPY statement.
Date: 2020-09-01 09:06:00
Message-ID: 7c20ba1b7dfee49de44be9399c2927790fec56b4.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

[redirected from -hackers]
On Tue, 2020-09-01 at 06:14 +0000, Junfeng Yang wrote:
> 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?

Your problem is that the file contains bad data.

You are using the default TEXT format of copy, and backslashes must
be escaped there.

Everything will work as you want if you write the first line correctly like

122,as\\.d,adad

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Junfeng Yang 2020-09-01 09:20:00 回复: Is it possible to set end-of-data marker for COPY statement.
Previous Message Kyotaro Horiguchi 2020-09-01 07:22:17 Re: How bad is using queries with thousands of values for operators IN or ANY?

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2020-09-01 09:16:06 Re: recovering from "found xmin ... from before relfrozenxid ..."
Previous Message Bernd Helmle 2020-09-01 08:54:52 Re: Documentation patch for backup manifests in protocol.sgml