Re: COPY vs \COPY FROM PROGRAM $$ quoting difference?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Alexander Stoddard <alexander(dot)stoddard(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: COPY vs \COPY FROM PROGRAM $$ quoting difference?
Date: 2017-09-29 16:54:25
Message-ID: CAKFQuwbspwwuFExChYek8QybzTj9VDyMv8fPfaBN6mg67Z27aA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Sep 29, 2017 at 9:27 AM, Alexander Stoddard <
alexander(dot)stoddard(at)gmail(dot)com> wrote:

> I found what seems to be an odd difference between COPY and \copy parsing.
>
​[...]

> COPY dest_table FROM PROGRAM $$ sed 's/x/y/' | etc... $$
>
> To my surprise this worked with COPY but not \COPY which failed with:
> \copy: parse error at "$$"
>
> Is this an undocumented difference? Is this even the appropriate email
> list to ask this kind of question or report such a difference?
>

​This is the correct place for seeking such clarification.​ The docs
cannot cover every possible thing people might do and these lists (-general
in particular) are here to fill in the gaps.

​The negative condition that "psql" itself doesn't understand
dollar-quoting​ is not documented. Dollar-quoting is documented as a
server-interpreted SQL Syntax feature and only applies there.

While the commands are similar COPY is server-side SQL while \copy is a
psql meta-command that psql converts to SQL, executes, obtains the results,
and processes. Note that the server would never see "PROGRAM $$" since the
server would be unable to access the local program being referred to. The
server sees "FROM stdin" and psql feeds the results of the PROGRAM
invocation to the server over that pipe.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Stoddard 2017-09-29 17:18:41 Re: COPY vs \COPY FROM PROGRAM $$ quoting difference?
Previous Message Alexander Stoddard 2017-09-29 16:27:39 COPY vs \COPY FROM PROGRAM $$ quoting difference?