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 1kD2ja-0007WS-AL for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 09:37:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kD2jY-0008OB-Iq for pgsql-general@arkaria.postgresql.org; Tue, 01 Sep 2020 09:37:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kD2jY-0008O3-AD for pgsql-general@lists.postgresql.org; Tue, 01 Sep 2020 09:37:44 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kD2jV-0003b8-Dr for pgsql-general@postgresql.org; Tue, 01 Sep 2020 09:37:43 +0000 Received: by mail-wr1-x42e.google.com with SMTP id f7so752109wrw.1 for ; Tue, 01 Sep 2020 02:37:41 -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=R9bPkmtvhz9HjatWB+yuwBqFau28bJI4pKm0XHIATic=; b=zPw98lfd/mVY1MTuHusSz/GKYf081cE9SGzy7rrLW44DE7Tln/OuSY6ReI6Nd9Ksme w8oTYPN3Jq+/6BmEdudSijj6gw9Mquat4cHLF4aY4cIvzJPgsnqlFjNckEZr2q2XcOcG vUPXU47arK+b5Ib5q+cPXdW4GRsjm9BtRHcA2XVnx3dmk6d/aOcFQbQ4WueDJhZKtM34 GYW9fZu3fde4zFxU9WO+BV0L/4JM2j2G58Nr/TraoJMwJ+WtsPlgo1blARDgYBTijFeP r9xUxeCS5I0fA37W9EINaIwor9jDN/0Cgx6uKSnzKUEjVUdEDmWGGN2jzyikiLP0FQbH cDMg== 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=R9bPkmtvhz9HjatWB+yuwBqFau28bJI4pKm0XHIATic=; b=VVFPkIlWfnABFtNoiGkefOge09YUAoI1xuyX7+xR/9jTtCtcr+7CKrVKG0scvW3AAx V7DY0mhFYcf9USem9+9dkYkoWwYtaXrDHhWp+UrtcVo1DTsCYehHZs0bEu4c4AdH55gJ 0hakhgZzIRs6ibIrn7euujaCsMZhWW1SqLrHD9YaWfLj6EB9rTxMlUadqF67dFmMSAit 3oQ1rFh45pngsxozaINMYlT7xB/VQvHL7L3Z4zdKH1v2YZX8klMII5xGkIgnLzYR/G36 hu3C5uauPX7vBzj7QKj4u2mgruJy2e1tzRgTFi9DXBDuKuICSpxaV3k+BgJt1STZbrtQ 9zKg== X-Gm-Message-State: AOAM531TbCWrca+nicNniHKsZiirw1WKgUx4ZDz/UMjfk8Zx7Q51ZfMr 9HFsKGG1PVevHOOiKrgSX/P4aQ== X-Google-Smtp-Source: ABdhPJyAkfS3BCS1qHZIDKfzb23RGJ/EHWOltgmBvpX+MaVWrXXOs7g2hACNgewdZg0vOrJf0wx3RQ== X-Received: by 2002:a5d:6a8e:: with SMTP id s14mr896090wru.44.1598953060204; Tue, 01 Sep 2020 02:37:40 -0700 (PDT) Received: from localhost.localdomain ([212.186.219.234]) by smtp.gmail.com with ESMTPSA id 21sm1488835wrc.55.2020.09.01.02.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 02:37:39 -0700 (PDT) Message-ID: Subject: Re: =?UTF-8?Q?=E5=9B=9E=E5=A4=8D=3A?= 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:37:38 +0200 In-Reply-To: References: ,<7c20ba1b7dfee49de44be9399c2927790fec56b4.camel@cybertec.at> 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: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Please, don't top-post on these lists. On Tue, 2020-09-01 at 09:20 +0000, Junfeng Yang wrote: > > 发件人: Laurenz Albe > > 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