Re: PQputCopyData dont signal error

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQputCopyData dont signal error
Date: 2011-04-14 07:50:16
Message-ID: 4DA6A738.1050907@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 14.04.2011 10:15, Pavel Stehule wrote:
> Hello
>
> I have a problem with PQputCopyData function. It doesn't signal some error.
>
> while ((row = mysql_fetch_row(res)) != NULL)
> {
> snprintf(buffer, sizeof(buffer), "%s%s\n", row[0], row[1]);
> copy_result = PQputCopyData(pconn, buffer, strlen(buffer));
> printf(">>%s<<\n", PQerrorMessage(pconn));
> printf("%d\n", copy_result);
> if (copy_result != 1)
> {
> fprintf(stderr, "Copy to target table failed: %s",
> PQerrorMessage(pconn));
> EXIT;
> }
> }
>
> it returns 1 for broken values too :(
>
> Is necessary some special check?

The way COPY works is that PQputCopyData just sends the data to the
server, and the server will buffer it in its internal buffer and
processes it when it feels like it. The PQputCopyData() calls don't even
need to match line boundaries.

I think you'll need to send all the data and finish the COPY until you
get an error. If you have a lot of data to send, you might want to slice
it into multiple COPY statements of say 50MB each, so that you can catch
errors in between.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-04-14 07:56:24 Re: PQputCopyData dont signal error
Previous Message Pavel Stehule 2011-04-14 07:15:23 PQputCopyData dont signal error