Re: Can't quote_literal with COPY FROM PROGRAM

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Mark Mikulec <mark(at)mikutech(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can't quote_literal with COPY FROM PROGRAM
Date: 2018-12-31 21:00:52
Message-ID: d18c27c2-72d4-15da-973a-c0fa90ff9714@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/31/18 12:58 PM, Mark Mikulec wrote:
> I changed it to be just the single float value I needed to extract out
> of the JSON object, but originally it was a text column that held the
> entire JSON object.

Might want to look at:

https://www.postgresql.org/docs/10/datatype-json.html

Might handle the escaping better.

> ᐧ
>
> On Mon, Dec 31, 2018 at 3:52 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
> On 12/31/18 9:36 AM, Mark Mikulec 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)
> >
> > C:\\Portable\\curl\\curl.exe -k
> >
> "https://maps.googleapis.com/maps/api/directions/json?etcVariablesDeleted"'
> >
> > 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"';
>
> So temp_maps_api has a single JSON field?
>
> >
> > 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
> > ᐧ
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gierth 2018-12-31 22:17:43 Re: Can't quote_literal with COPY FROM PROGRAM
Previous Message Mark Mikulec 2018-12-31 20:58:46 Re: Can't quote_literal with COPY FROM PROGRAM