Skip site navigation (1) Skip section navigation (2)

Re: Copy command not writing complete data to text file

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Kevin Keith <kevinrkeith(at)hotmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Copy command not writing complete data to text file
Date: 2005-09-22 23:56:54
Message-ID: 20050922235654.GA25552@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-admin
On Thu, Sep 22, 2005 at 11:49:24AM -0500, Kevin Keith wrote:
> It is a CGI (shell) script that is calling a C program. I found the issue - 
> which was external to Postgres.

So what was it?  Even if it wasn't a PostgreSQL problem it might
be educational to learn what happened.

> I still have one remaining question - if the COPY to FILE command fails, 
> does it return an error? If the program uses:
> int i;
> i = PQexec("copy from <<table_name>> to <<fully_qualified_file_name>>");
> 
> and the table has (for example) 500 records, but only 350 were copied to 
> the file, what is returned in i?

PQexec() returns a PGresult *, not an int.  You can pass that PGresult *
to PQresultStatus() to find out the command's status; if the command
failed you can pass the PGresult * to PQresultErrorMessage() to get
a descriptive error message.  See the libpq documentation for more
information.

On success, COPY returns a result status of PGRES_COMMAND_OK; I'd
expect it to return something else if it failed.  For example, if
the disk is full then COPY fails with PGRES_FATAL_ERROR.  If you
have a case where COPY reports success but writes an incomplete
file then please post the code -- that way we can see if the bug
is in your code or in PostgreSQL.

-- 
Michael Fuhr

In response to

pgsql-admin by date

Next:From: Steuckrath, Randy ADate: 2005-09-23 00:29:59
Subject: PgAdmin3 1.2.2 Install on Win32 Disrupts Pg Service
Previous:From: Scott MarloweDate: 2005-09-22 23:51:35
Subject: Re: alter user

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group