X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 17B42D71F1 for ; Thu, 22 Sep 2005 20:58:16 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54448-07 for ; Thu, 22 Sep 2005 23:58:10 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 99BB0D6ECD for ; Thu, 22 Sep 2005 20:58:10 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j8MNutUx057467 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Sep 2005 17:56:57 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j8MNusu4025642; Thu, 22 Sep 2005 17:56:54 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j8MNusQT025641; Thu, 22 Sep 2005 17:56:54 -0600 (MDT) (envelope-from mfuhr) Date: Thu, 22 Sep 2005 17:56:54 -0600 From: Michael Fuhr To: Kevin Keith Cc: pgsql-admin@postgresql.org Subject: Re: Copy command not writing complete data to text file Message-ID: <20050922235654.GA25552@winnie.fuhr.org> References: <20050922145236.GA96171@winnie.fuhr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 required=5 tests=[AWL=0.005] X-Spam-Level: X-Archive-Number: 200509/246 X-Sequence-Number: 18983 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 <> to <>"); > > 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