pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Niels Laakmann <nielsson@grillen23.de>
To: pgsql-interfaces@postgresql.org
Subject: Re: ECPG and COPY FROM STDIN
Date: Thu, 23 Nov 2006 14:57:27 +0100
Message-ID: <20061123135805.286DA77A78@mail.toxisch.net> (raw)
In-Reply-To: <200611200642.23872.sdavis2@mail.nih.gov>
References: <20061120111317.9889D77A3B@mail.toxisch.net>
	<200611200642.23872.sdavis2@mail.nih.gov>

Am heiligen Mo, 20 November 2006 06:42:23 -0500
schrieb Sean Davis <sdavis2@mail.nih.gov>:

> On Monday 20 November 2006 06:12, Niels Laakmann wrote:
> > Hey List!
> > I have to do a Benchmark-Test in C (ECPG) with and without network.
> > After reading the Performance and COPY Documentation (not correctly), I
> > wanted to Copy a File over the Network by using "COPY FROM 'filename'".
> > After some curious Problems I knew why.
> > Now I read some about "COPY FROM STDIN. But I didn't find an Example.
> > Can someone please give me an Example for that ?
> >
> > Or:
> >
> > Is there another command to insert many tuples from a Client to a
> > Server in an adequate time ?
> 
> How about here:
> 
> http://www.postgresql.org/docs/8.1/interactive/libpq-copy.html

At first thanks for this Tipp. I rewrite my Code to use Libpq now. But
the next Problem comes up:

<snap>
char textbuffer[120];

result = PQexec(connect, "COPY branches (branchid, branchname, balance,
   address) FROM STDIN WITH DELIMITER ',';");

if(PQresultStatus(result) != PGRES_COPY_IN)
   shutdown_conn(1, connect);		//my own error-handling
                                        //function

for(n=0; n < count_tupel; n++) {
   sprintf(textbuffer, "%d,text1,0,text2", n);
   if(PQputCopyData(connect, textbuffer, strlen(textbuffer) + 1) != 1)
      shutdown_conn(1, connect); 
}
   PQputCopyEnd(connect, NULL);
   PQgetResult(connect);
</snap>

If count_tupel is 1, one Tupel is inserted to the relation. If
count_tupel is greater than 1. No Tupel is inserted and I got the
Error-Message: "extra data after last expected column".
What are we doing wrong ? - Is there something wrong as I discard the
buffer ? - A Null-Termination etc. ?

The other thing is, that I've looked for some libpq-copy - examples.
But neither in the postgresql-src nor on some postgres-related
internet-pages, I found one.

Can anyone help ?
- Thanks -

Niels


> 
> Sean
> 



view thread (4+ messages)  latest in thread

Message-ID: <20061123135805.286DA77A78@mail.toxisch.net>
Permalink:  ../20061123135805.286DA77A78@mail.toxisch.net/
Also on:    postgresql.org/message-id/20061123135805.286DA77A78@mail.toxisch.net

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: nielsson@grillen23.de
  Subject: Re: ECPG and COPY FROM STDIN
  In-Reply-To: <20061123135805.286DA77A78@mail.toxisch.net>

* 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