From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Mark Mikulec <mark@mikutech.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Can't quote_literal with COPY FROM PROGRAM
Date: Mon, 31 Dec 2018 22:17:43 +0000
Message-ID: <8736qdtlff.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CA+aX0ec8ZkPhm4cnV7mCVJqkUGRLGfZLbB5+snveD-33GOgnLg@mail.gmail.com>
References: <CA+aX0efk8+9WAHGsC8vtiuxPsZPik=aUUHrPXyp5L7Kq9HNLHA@mail.gmail.com>
<D993AA73-7662-4EF9-ADF5-109585A5815A@gmail.com>
<CA+aX0ec8ZkPhm4cnV7mCVJqkUGRLGfZLbB5+snveD-33GOgnLg@mail.gmail.com>
>>>>> "Mark" == Mark Mikulec <mark@mikutech.com> 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: andrew@tao11.riddles.org.uk, mark@mikutech.com, robjsargent@gmail.com
Subject: Re: Can't quote_literal with COPY FROM PROGRAM
In-Reply-To: <8736qdtlff.fsf@news-spur.riddles.org.uk>
References: <CA+aX0efk8+9WAHGsC8vtiuxPsZPik=aUUHrPXyp5L7Kq9HNLHA@mail.gmail.com> <D993AA73-7662-4EF9-ADF5-109585A5815A@gmail.com> <CA+aX0ec8ZkPhm4cnV7mCVJqkUGRLGfZLbB5+snveD-33GOgnLg@mail.gmail.com> <8736qdtlff.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox