Re: COPY statement cannot take binding parameters

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Stephen R(dot) van den Berg" <srb(at)cuci(dot)nl>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY statement cannot take binding parameters
Date: 2008-09-03 01:23:40
Message-ID: 9951.1220405020@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Stephen R. van den Berg" <srb(at)cuci(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Brendan Jurd 2008-09-03 01:34:33 Re: What is the use of the CommitFestBlank template?
Previous Message Tom Lane 2008-09-03 00:55:14 Re: What is the use of the CommitFestBlank template?