pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Junfeng Yang <yjerome@vmware.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: 回复: Is it possible to set end-of-data marker for COPY statement.
Date: Tue, 01 Sep 2020 11:37:38 +0200
Message-ID: <ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at> (raw)
In-Reply-To: <DM5PR0501MB3880FDA797B41976E9473A00CC2E0@DM5PR0501MB3880.namprd05.prod.outlook.com>
References: <DM5PR0501MB3880CB81067E14F9C78FA28BCC2E0@DM5PR0501MB3880.namprd05.prod.outlook.com>
	<7c20ba1b7dfee49de44be9399c2927790fec56b4.camel@cybertec.at>
	<DM5PR0501MB3880FDA797B41976E9473A00CC2E0@DM5PR0501MB3880.namprd05.prod.outlook.com>

Please, don't top-post on these lists.

On Tue, 2020-09-01 at 09:20 +0000, Junfeng Yang wrote:
> 
> 发件人: Laurenz Albe <laurenz.albe@cybertec.at>
> > On Tue, 2020-09-01 at 06:14 +0000, Junfeng Yang wrote:
> > > As described in the doc , 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
>
> I understand `\\.` should work. But this requires users to modify huge data.
> I'm wondering is it possible to change the default end-of-data marker or
> could we implement a method to let users choose their own marker?

I don't see the problem.

If you use the CSV format, your data will work fine the way they are:

  COPY test FROM '/tmp/data' (FORMAT 'csv');

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






view thread (8+ messages)  latest in thread

Message-ID: <ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at>
Permalink:  ../ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at/
Also on:    postgresql.org/message-id/ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at

 · 

reply

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: laurenz.albe@cybertec.at, yjerome@vmware.com
  Subject: Re: 回复: Is it possible to set end-of-data marker for COPY statement.
  In-Reply-To: <ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at>
  References: <DM5PR0501MB3880CB81067E14F9C78FA28BCC2E0@DM5PR0501MB3880.namprd05.prod.outlook.com> <7c20ba1b7dfee49de44be9399c2927790fec56b4.camel@cybertec.at> <DM5PR0501MB3880FDA797B41976E9473A00CC2E0@DM5PR0501MB3880.namprd05.prod.outlook.com> <ac6783e3d01d2dfb7061eaa1b2e4a02468c94b6b.camel@cybertec.at>

* 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