pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++
2+ messages / 2 participants
[nested] [flat]

* BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++
@ 2021-09-19 09:17 PG Bug reporting form <noreply@postgresql.org>
  2021-09-19 15:08 ` Re: BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++ Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2021-09-19 09:17 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: stankiewiczal@gmail.com

The following bug has been logged on the website:

Bug reference:      17195
Logged by:          Aleksander Stankiewicz
Email address:      stankiewiczal@gmail.com
PostgreSQL version: 13.4
Operating system:   Windows
Description:        

I have test table like below:

  --DROP TABLE test_point
  CREATE TABLE test_point(
    serie_id       INT               NOT NULL,
    version_ts     INT               NOT NULL,
    PRIMARY KEY (serie_id, version_ts)
  );

I try to use parametrized query inside COPY TO statement. Te test case
showing the issue is below.
When I execute this short test I receive such message:
0x0000027645b28dc0 "ERROR:  bind message supplies 1 parameters, but prepared
statement \"\" requires 0\n"

Test case:
TEST(TSStorage, CopyParamTest)
{
    auto sql = "COPY(SELECT version_ts FROM test_point WHERE serie_id =
$1::int) TO STDOUT (FORMAT binary)";
    auto connPtr =
PQconnectdb("postgresql://postgres:pswd@localhost/test_db");

    int seriesIdParam = htonl(5); // or just put 5 directly here - doesn't
matter for the statement compilation here

    const char *paramValues[] = {(const char *)&seriesIdParam};
    const int paramLengths[] = {sizeof(seriesIdParam)};
    const int paramFormats[] = {1}; // 1 means binary

    auto result = PQexecParams(connPtr,
                          sql,
                          1, //nParams,
                          nullptr,
                          paramValues,
                          paramLengths,
                          paramFormats,
                          1); // Output format - binary

    // Ensure it's in COPY_OUT state
    if (PQresultStatus(result) != PGRES_COPY_OUT)
    {
        auto errorMsg = PQerrorMessage(connPtr);
        int set_breakpoint_here = 0;
    }

    PQclear(result);
    PQfinish(connPtr);
}

How to provide param for binding there?
When I use sql without COPY statement there it recognizes param without any
problems.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++
  2021-09-19 09:17 BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++ PG Bug reporting form <noreply@postgresql.org>
@ 2021-09-19 15:08 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-09-19 15:08 UTC (permalink / raw)
  To: stankiewiczal@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
>     auto sql = "COPY(SELECT version_ts FROM test_point WHERE serie_id =
> $1::int) TO STDOUT (FORMAT binary)";

Don't hold your breath for that to work :-(.  Utility statements in
general do not support parameterization.  COPY is not an exception,
even when it contains what looks like a full DML command.  Maybe
somebody will improve that someday, but we'll certainly treat it
as a new feature not a bug fix.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-09-19 15:08 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 09:17 BUG #17195: Can't bind $1::int param when I use COPY TO STDOUT statement - libpq, C++ PG Bug reporting form <noreply@postgresql.org>
2021-09-19 15:08 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox