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 1oN7cP-0004dj-NE for pgsql-bugs@arkaria.postgresql.org; Sun, 14 Aug 2022 07:01:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oN7cN-0006Dn-1A for pgsql-bugs@arkaria.postgresql.org; Sun, 14 Aug 2022 07:01:03 +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 1oN7cM-0006De-Hj for pgsql-bugs@lists.postgresql.org; Sun, 14 Aug 2022 07:01:02 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oN7cJ-0006Qe-9R for pgsql-bugs@lists.postgresql.org; Sun, 14 Aug 2022 07:01:01 +0000 Received: by mail-qk1-x72f.google.com with SMTP id c28so3649728qko.9 for ; Sun, 14 Aug 2022 00:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc; bh=ez98WW8XoiOKwhaugeJE7/kMqWk+F9W1ccUzjL1/Wi4=; b=IFtAzV9mYJ9ehc6F3kaN7UXalTjyO2qdqza7NWv9fx2w4JRxISfmiPaXWgfM8OvP4r XfnVfRaEjK1cvVBAxtkoK3wL2nnynUcI+//ut1JQgk/+iSHJuPZPYo17Lixr26TOrH3S f2njjfGw7FVrzK2kR4fknuoqr+Hhew/IXSzeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=ez98WW8XoiOKwhaugeJE7/kMqWk+F9W1ccUzjL1/Wi4=; b=wa/GPlfCtHVagKEzfhaoBILV+bW5EroLzKSdX8aiC6sSTrnlsEkERjn39EbKIRPEPi EfpAWG/HNg+AykyWTq46VB0SQSJSPt9echegzqFtNFGvxNmMsgWhBtjjyfQhTS8UiEJZ wAAv1Q5DfzpbHxJ9xRztcDw3TDrzf6IpjtyYXg3j64xW42szCZcgfkru9zLdChWxaIDH ADgvCMVxq7Zn7eRGNOVqSqNwz7d6N66WkkuvcxNYI081QhFHWvXQ9h0am2u3/jrIXx8D HGs2qSczFw3roxwwqdpAuoY/hbOYWwiAEcZxRi7qsPluuF45MQVixF9NOHv50psHwmo5 Y7eQ== X-Gm-Message-State: ACgBeo0pWUM4AwjgjNG14bPpD/wsA+6hBoWm8sXc0qRXqcHwWBWev4k8 EF9pqg9fdbblAJNnVNnxI96uJLwZyNkMgQ== X-Google-Smtp-Source: AA6agR7R8psvjGLOxKYRfaSOkvwynSwv04RnP2qkhwukmtgdCWrFb9P76k/9rmHyTkDMlDJcDCueVg== X-Received: by 2002:a05:620a:261d:b0:6bb:fa6:1ad6 with SMTP id z29-20020a05620a261d00b006bb0fa61ad6mr1442263qko.65.1660460457061; Sun, 14 Aug 2022 00:00:57 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id fy11-20020a05622a5a0b00b0031ea864d3b2sm5388643qtb.30.2022.08.14.00.00.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Aug 2022 00:00:56 -0700 (PDT) Date: Sun, 14 Aug 2022 00:00:53 -0700 From: Noah Misch To: Svante Richter Cc: pgsql-bugs@lists.postgresql.org Subject: Re: COPY TO CSV produces data that is incompatible/unsafe for \COPY FROM CSV Message-ID: <20220814070053.GA92855@rfd.leadboat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jun 15, 2022 at 02:16:14PM +0200, Svante Richter wrote: > The documentation for COPY says "To avoid any misinterpretation, a `\.` data value appearing as a lone entry on a line is automatically quoted on output, and on input, if quoted, is not interpreted as the end-of-data marker". > > The input part only seems to work when using the COPY FROM CSV command, not \COPY FROM CSV. This is mentioned in a previous message here https://www.postgresql.org/message-id/a89f47e1-f716-4ae3-b882-cab5032a5d66%40manitou-mail.org but not documented. I agree this warrants a doc mention. Also, the previous thread seems to have ended with a focus on [\copy ... from stdin], but it's broader than that: > COPY testtable FROM '/run/postgresql/test.csv' CSV; -- This one works > \COPY testtable FROM '/run/postgresql/test.csv' CSV; -- This one does not work The psql documentation says [\copy ... from stdin] looks for "\.". It says nothing about doing that for [\copy ... from filename]. I wonder if psql should change the filename case to send the whole file to the server, ignoring "\." inside. (That is to say, change to match the psql documentation.) This, too, has an avoidable case of the problem: create table t (c text); \copy t from program 'printf ''"foo\n\\.\nbar"''' with csv