Re: problem with PQsendQuery/PQgetResult and COPY FROM statement - Mailing list pgsql-hackers

From Tom Lane
Subject Re: problem with PQsendQuery/PQgetResult and COPY FROM statement
Date
Msg-id 731.1148497597@sss.pgh.pa.us
Whole thread Raw
In response to Re: problem with PQsendQuery/PQgetResult and COPY FROM statement  (max.poletto@gmail.com)
Responses Re: problem with PQsendQuery/PQgetResult and COPY FROM statement
List pgsql-hackers
max.poletto@gmail.com writes:
> I do not expect PQgetResult to return millions of non-null PGresult
> objects after a PQsendQuery("COPY test FROM STDIN").  I expect exactly
> one non-null result, with a result status of PGRES_COPY_IN.

If you call it exactly once, it'll say that exactly once.  If you keep
calling it "millions of times", it'll keep saying that.

> Moreover, the manual says:

>    If a COPY command is issued via PQexec in a string that could
> contain
>    additional commands, the application must continue fetching results
>    via PQgetResult after completing the COPY sequence. Only when
>    PQgetResult returns NULL is it certain that the PQexec command
> string
>    is done and it is safe to issue more commands.

Indeed.  You forgot to "complete the COPY sequence" before returning
to the PQgetResult loop.  As long as the thing is in COPY mode,
PQgetResult will return a result saying PGRES_COPY_IN.  The point
of this paragraph is that you might want to consider doing more
PQgetResults *after* you've ended COPY mode.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Re: Why is CVS server so slow?
Next
From: "Dave Page"
Date:
Subject: Re: Why is CVS server so slow?