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

From Mark Mikulec
Subject Re: Can't quote_literal with COPY FROM PROGRAM
Date
Msg-id CA+aX0ec8ZkPhm4cnV7mCVJqkUGRLGfZLbB5+snveD-33GOgnLg@mail.gmail.com
Whole thread Raw
In response to Re: Can't quote_literal with COPY FROM PROGRAM  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: Can't quote_literal with COPY FROM PROGRAM
List pgsql-general
Thanks Rob,

Since I'm on Windows and Windows batch sucks I just ended up doing the JSON parsing with node.js

To be honest this whole affair with COPY FROM program seems like a bug to me though.

On Mon, Dec 31, 2018 at 1:59 PM Rob Sargent <robjsargent@gmail.com> wrote:


On Dec 31, 2018, at 10:36 AM, Mark Mikulec <mark@mikutech.com> wrote:

Hi,

This command, which generates a JSON object as output, has some escaped data with backslashes: (see line 91 here: https://pastebin.com/D4it8ybS)


I use the COPY command to pull it into a temp table like so:

COPY temp_maps_api from program 'C:\\Portable\\curl\\curl.exe -k "https://maps.googleapis.com/maps/api/directions/json?etcVariablesDeleted"';

However copy eats those backslashes. I need to use quote_literal() but that's a syntax error. For some reason the COPY command doesn't allow for ESCAPE to work with programs, only CSV.

I tried using WITH BINARY but I get the error message: "COPY file signature not recognized"

Does anyone know how to make COPY FROM PROGRAM take the output literally?

Thanks,
  Mark
Can you pipe the curl output through sed s,\\,\\\\,g 

pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Can't quote_literal with COPY FROM PROGRAM
Next
From: Adrian Klaver
Date:
Subject: Re: Can't quote_literal with COPY FROM PROGRAM