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 1kD2F2-00068Y-7H for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 09:06:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kD2F1-0006ES-0d for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 09:06:11 +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 1kD2F0-0006EL-K3 for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 09:06:10 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kD2Eu-0005sw-6C for pgsql-general@postgresql.org; Tue, 01 Sep 2020 09:06:09 +0000 Received: by mail-wm1-x336.google.com with SMTP id a65so372447wme.5 for ; Tue, 01 Sep 2020 02:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=v4HNRvGsG/Czn24z7TJ3f5t/j8TJtpOZoFu/6uXVezQ=; b=vujXdbXrunGYJMgiMTypxDktsoS1tSS9/P31X8+PE02fUEVaVG3WaFiN5xpeKMzAlM A3dmO6rw0kPR3uQoqFlWCcOd+Fcz4qupLbLDq8LqHoIQU7ZNSGRuWGSMrr7dpp6qG0LT x/iDWqZNZ++t7i2iOV+WGHLY4xpUCUtuXisQqfbaJTYZkoVOToDfHr9ZkmsBeaZJMZNk nvI55NnWIGBGz/HkOSk0kAy36PNQ/k6dLZYaw5W4/MgFpI/qbPvJiszBfmTfRdVO0lrw j4ts6YS1+DpySKYBLWMLS+IU9fCtwkre4prvYyNBq/xPqbvVIkEK5jMegG73BfFJcugc 9RKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=v4HNRvGsG/Czn24z7TJ3f5t/j8TJtpOZoFu/6uXVezQ=; b=JuLKwsvNisrUl43Em0So/mahwRhyP/6S9yEz71I0W4GgdEghHgr7GyQdB2PfSvkNyh rngmmkjj/nzr26q5gXFkVXjBG5A4fMz4KzrDVJJXGfqd4NUjHNPy4nuAGkJ6N13csza2 rTIyafQotOiTbNykgWVDk8W+qJVbhAMkVuYQXrV2ObjlzAMXntfkVm0ANVwODHIc0aOj fTuESiCgCWoMRCECI+LE74JNlM4bXw/TGFlFvTKC9yvqIAVEm7PMHm3U84882coxdAnE /+cxL06Me/OAy4Q7Nb6Q2pDa0BZ1ih9OidVpsDHnDxdJ+J8TQZ64EVPGcp1THg7ecWtm 1ZMg== X-Gm-Message-State: AOAM532wg12PGrvzKrLDY5PL9yEZUG4ucCC+mP6zq8UiydkWD31HkibJ iuggphke9E6UQ6+QICkDZo32AA== X-Google-Smtp-Source: ABdhPJxyLEQomSakUIkLpY4ATCjm39QTsAKbXSIiR3NyVecectmoRqUDC6OAsaIv/vXV0+JjIQAVzQ== X-Received: by 2002:a1c:23c8:: with SMTP id j191mr770028wmj.64.1598951162313; Tue, 01 Sep 2020 02:06:02 -0700 (PDT) Received: from localhost.localdomain ([212.186.219.234]) by smtp.gmail.com with ESMTPSA id o125sm968195wma.27.2020.09.01.02.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 02:06:01 -0700 (PDT) Message-ID: <7c20ba1b7dfee49de44be9399c2927790fec56b4.camel@cybertec.at> Subject: Re: Is it possible to set end-of-data marker for COPY statement. From: Laurenz Albe To: Junfeng Yang , pgsql-general@postgresql.org Date: Tue, 01 Sep 2020 11:06:00 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk [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