pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Kevin Keith <kevinrkeith@hotmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Copy command not writing complete data to text file
Date: Thu, 22 Sep 2005 17:56:54 -0600
Message-ID: <20050922235654.GA25552@winnie.fuhr.org> (raw)
In-Reply-To: <BAY108-F22058BC80EF93E11A0448FB9970@phx.gbl>
References: <20050922145236.GA96171@winnie.fuhr.org>
	<BAY108-F22058BC80EF93E11A0448FB9970@phx.gbl>

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



view thread (4+ messages)

Message-ID: <20050922235654.GA25552@winnie.fuhr.org>
Permalink:  ../20050922235654.GA25552@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050922235654.GA25552@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mike@fuhr.org, kevinrkeith@hotmail.com
  Subject: Re: Copy command not writing complete data to text file
  In-Reply-To: <20050922235654.GA25552@winnie.fuhr.org>
  References: <20050922145236.GA96171@winnie.fuhr.org> <BAY108-F22058BC80EF93E11A0448FB9970@phx.gbl> <20050922235654.GA25552@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox