Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ge5sc-0002hT-VV for pgsql-general@arkaria.postgresql.org; Mon, 31 Dec 2018 22:17:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ge5sb-0007BA-Ln for pgsql-general@arkaria.postgresql.org; Mon, 31 Dec 2018 22:17:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ge5sb-00073h-8A for pgsql-general@lists.postgresql.org; Mon, 31 Dec 2018 22:17:49 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ge5sZ-0003gj-3t for pgsql-general@postgresql.org; Mon, 31 Dec 2018 22:17:48 +0000 Received: from [192.168.127.1] (port=17930 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1ge5sW-0001i4-0v; Mon, 31 Dec 2018 22:17:44 +0000 Received: from [127.0.0.1] (port=24587 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1ge5sV-000CJe-A7; Mon, 31 Dec 2018 22:17:43 +0000 From: Andrew Gierth To: Mark Mikulec Cc: Rob Sargent , pgsql-general@postgresql.org Subject: Re: Can't quote_literal with COPY FROM PROGRAM In-Reply-To: (Mark Mikulec's message of "Mon, 31 Dec 2018 15:50:11 -0500") Message-ID: <8736qdtlff.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Mon, 31 Dec 2018 22:17:43 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Mark" == Mark Mikulec writes: Mark> To be honest this whole affair with COPY FROM program seems like Mark> a bug to me though. Perhaps you're misunderstanding what COPY FROM PROGRAM is actually for. Its purpose is to do exactly what COPY does, that is to say, take as input a file in either PG's tab-delimited format or in CSV format, break it into records and fields, and insert the data into a table. Note that JSON is not a supported input format for COPY, though of course JSON _values_ can appear as data within a field inside either the tab-delimited or CSV formats. COPY FROM PROGRAM simply does COPY but with the input (whether in tab or CSV format) taken from the output of the program rather than a file. In tab-delimited format, the delimiter can be changed to something other than a tab, but the escape character is fixed as \ and the characters NL, CR, \, and the delimiter character are required to be escaped. Thus, any literal \ in the data MUST be escaped as \\ before passing the data to COPY in this mode. In CSV mode, CSV quoting and escaping rules are followed. It's not COPY's job to read a single datum, whether in JSON format or anything else. -- Andrew (irc:RhodiumToad)