Re: PQputCopyData dont signal error - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: PQputCopyData dont signal error
Date
Msg-id 4DA6A738.1050907@enterprisedb.com
Whole thread Raw
In response to PQputCopyData dont signal error  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: PQputCopyData dont signal error  (Jeff Davis <pgsql@j-davis.com>)
List 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


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: PQputCopyData dont signal error
Next
From: Andrew Dunstan
Date:
Subject: Re: Itanium HP-UX build failure, register stack