Re: COPY statement cannot take binding parameters - Mailing list pgsql-hackers

From Tom Lane
Subject Re: COPY statement cannot take binding parameters
Date
Msg-id 9951.1220405020@sss.pgh.pa.us
Whole thread Raw
In response to COPY statement cannot take binding parameters  ("Stephen R. van den Berg" <srb@cuci.nl>)
List pgsql-hackers
"Stephen R. van den Berg" <srb@cuci.nl> writes:
> Trying to parse and bind the following:
>    COPY (SELECT $1::INT) TO STDOUT
> gives a correct parsing-done, but then in the parameterdescription tells
> me that there are no parameters.

> Is this intended?

It's an artifact of the klugy way that SELECT was shoehorned into COPY :-(.
The SELECT isn't actually parsed/planned until execution time, so there
is no opportunity even to notice that it contains parameter symbols,
much less identify their types.  If you experiment you'll soon see that
any but the most basic syntactical errors in the SELECT aren't reported
at Parse-message time.

It might be possible to fix that by inverting the structure of the
statement internally, turning it into something approximating
SELECT ... INTO <copy parameters here> FROM ...

where IntoClause or some equivalent is made to carry everything from the
outer COPY syntax.  Don't hold your breath though.  (I think the parser
changes would actually be pretty trivial, but it might take some major
refactoring of the COPY code to let it be driven entirely as a tuple
receiver.)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: What is the use of the CommitFestBlank template?
Next
From: "Brendan Jurd"
Date:
Subject: Re: What is the use of the CommitFestBlank template?