Re: problem with PQsendQuery/PQgetResult and COPY FROM statement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: max(dot)poletto(at)gmail(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: problem with PQsendQuery/PQgetResult and COPY FROM statement
Date: 2006-05-24 19:06:37
Message-ID: 731.1148497597@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

max(dot)poletto(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2006-05-24 19:16:23 Re: Why is CVS server so slow?
Previous Message Marc G. Fournier 2006-05-24 19:05:59 Re: Why is CVS server so slow?