Re: Can't quote_literal with COPY FROM PROGRAM - Mailing list pgsql-general

From Andrew Gierth
Subject Re: Can't quote_literal with COPY FROM PROGRAM
Date
Msg-id 8736qdtlff.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: Can't quote_literal with COPY FROM PROGRAM  (Mark Mikulec <mark@mikutech.com>)
List pgsql-general
>>>>> "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)


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Can't quote_literal with COPY FROM PROGRAM
Next
From: Adrian Klaver
Date:
Subject: Re: Relocatable Binaries (RPMs) : custom installation path forPostgreSQL