Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDA2d-0003Vm-GP for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Sep 2020 17:25:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kDA2c-00046l-Ee for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Sep 2020 17:25:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDA2c-00046e-7s for pgsql-hackers@lists.postgresql.org; Tue, 01 Sep 2020 17:25:54 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDA2a-0001wH-2q for pgsql-hackers@lists.postgresql.org; Tue, 01 Sep 2020 17:25:53 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1kDA2Y-0000Kl-VK; Tue, 01 Sep 2020 13:25:50 -0400 Date: Tue, 1 Sep 2020 13:25:50 -0400 From: Bruce Momjian To: Junfeng Yang Cc: "pgsql-hackers@postgresql.org" Subject: Re: Is it possible to set end-of-data marker for COPY statement. Message-ID: <20200901172550.GY13613@momjian.us> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee