Lists: | Postg윈 토토SQL : Postg윈 |
---|
From: | Niels Laakmann <nielsson(at)grillen23(dot)de> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | ECPG and COPY FROM STDIN |
Date: | 2006-11-20 11:12:41 |
Message-ID: | 20061120111317.9889D77A3B@mail.toxisch.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg윈 토토SQL : Postg윈 |
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 ?
Niels
From: | Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Cc: | Niels Laakmann <nielsson(at)grillen23(dot)de> |
Subject: | Re: ECPG and COPY FROM STDIN |
Date: | 2006-11-20 11:42:23 |
Message-ID: | 200611200642.23872.sdavis2@mail.nih.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-interfaces |
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
Sean
From: | Niels Laakmann <nielsson(at)grillen23(dot)de> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: ECPG and COPY FROM STDIN |
Date: | 2006-11-23 13:57:27 |
Message-ID: | 20061123135805.286DA77A78@mail.toxisch.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-interfaces |
Am heiligen Mo, 20 November 2006 06:42:23 -0500
schrieb Sean Davis <sdavis2(at)mail(dot)nih(dot)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
>
From: | Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> |
---|---|
To: | Niels Laakmann <nielsson(at)grillen23(dot)de> |
Cc: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: ECPG and COPY FROM STDIN |
Date: | 2006-11-23 15:39:19 |
Message-ID: | 4565C0A7.5030904@mail.nih.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-interfaces |
Niels Laakmann wrote:
> Am heiligen Mo, 20 November 2006 06:42:23 -0500
> schrieb Sean Davis <sdavis2(at)mail(dot)nih(dot)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. ?
>
You need to have each line end in "\n"; the line needs to be a line,
just like you would print to the screen.
Sean