pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedupdate by one transaction
4+ messages / 3 participants
[nested] [flat]
* update by one transaction
@ 1998-06-11 08:16 Lendvary Gyorgy <gyurika@prolan.hu>
1998-06-11 08:54 ` Re: [SQL] update by one transaction Aleksey Dashevsky <postgres@luckynet.co.il>
0 siblings, 1 reply; 4+ messages in thread
From: Lendvary Gyorgy @ 1998-06-11 08:16 UTC (permalink / raw)
To: pgsql-sql
Hello,
I have tried to write my problem, but I think nobody couldn,t understand
it (because of my bad English, I think).
I have a table for instance boci (row_number int, col2 float, col3
float). The boci table has about 10000 rows.
I want to update col3 column of the table in every row with different
values. Desired values are in an array has 10000 elements. I want to be
the value of the col3 column in the first row equal to the first element
of the array and so on.
I've done it with a 'for' cycle, but it is very slow. I want to do
theese updates with one transaction.
Here is a little piece of my program:
for (i=0; i<10000; i++)
{
sprintf(buff, "UPDATE boci SET col3 = %f WHERE row_number=%d",
array[i], i);
PQexec(conn, buff);
}
PQexec(conn, "COMMIT");
This program is very, very slow. Is there any way making this program
much faster (for instance with CURSOR or 'block write' or something
else)? Please write me a little program that describes your ideas!
Thanks for your help in advance!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] update by one transaction
1998-06-11 08:16 update by one transaction Lendvary Gyorgy <gyurika@prolan.hu>
@ 1998-06-11 08:54 ` Aleksey Dashevsky <postgres@luckynet.co.il>
0 siblings, 0 replies; 4+ messages in thread
From: Aleksey Dashevsky @ 1998-06-11 08:54 UTC (permalink / raw)
To: Lendvary Gyorgy <gyurika@prolan.hu>; +Cc: pgsql-sql
On Thu, 11 Jun 1998, Lendvary Gyorgy wrote:
> Hello,
>
> I have tried to write my problem, but I think nobody couldn,t understand
> it (because of my bad English, I think).
>
> I have a table for instance boci (row_number int, col2 float, col3
> float). The boci table has about 10000 rows.
> I want to update col3 column of the table in every row with different
> values. Desired values are in an array has 10000 elements. I want to be
> the value of the col3 column in the first row equal to the first element
> of the array and so on.
> I've done it with a 'for' cycle, but it is very slow. I want to do
> theese updates with one transaction.
>
> Here is a little piece of my program:
>
> for (i=0; i<10000; i++)
> {
> sprintf(buff, "UPDATE boci SET col3 = %f WHERE row_number=%d",
> array[i], i);
> PQexec(conn, buff);
> }
> PQexec(conn, "COMMIT");
>
> This program is very, very slow. Is there any way making this program
> much faster (for instance with CURSOR or 'block write' or something
> else)? Please write me a little program that describes your ideas!
>
> Thanks for your help in advance!
>
It seems you simply forgot to start transaction before the loop. So you
need to prepend this code with begin statement:
PQexec(conn, "BEGIN");
Hope, this will help!
Aleksey.
^ permalink raw reply [nested|flat] 4+ messages in thread
* update by one transaction
@ 1998-06-11 13:26 Lendvary Gyorgy <gyurika@prolan.hu>
1998-06-11 17:06 ` Re: [SQL] update by one transaction dave madden <dhm@paradigm.webvision.com>
0 siblings, 1 reply; 4+ messages in thread
From: Lendvary Gyorgy @ 1998-06-11 13:26 UTC (permalink / raw)
To: pgsql-sql
BEGIN isn't the solution, just I forgot to write it. So I repeat my
problem again:
I have a table for instance boci (row_number int, col2 float, col3
float). The boci table has about 10000 rows.
I want to update col3 column of the table in every row with different
values. Desired values are in an array has 10000 elements. I want to be
the value of the col3 column in the first row equal to the first element
of the array and so on.
I've done it with a 'for' cycle, but it is very slow. I want to do
theese updates with one transaction.
Here is a little piece of my program:
PQexec(conn, "BEGIN");
for (i=0; i<10000; i++)
{
sprintf(buff, "UPDATE boci SET col3 = %f WHERE row_number=%d",
array[i], i);
PQexec(conn, buff);
}
PQexec(conn, "END");
This program is very, very slow. Is there any way making this program
much faster (for instance with CURSOR or 'block write' or something
else)? Please write me a little program that describes your ideas!
Thanks for your help in advance!
Please help me!!!
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] update by one transaction
1998-06-11 13:26 update by one transaction Lendvary Gyorgy <gyurika@prolan.hu>
@ 1998-06-11 17:06 ` dave madden <dhm@paradigm.webvision.com>
0 siblings, 0 replies; 4+ messages in thread
From: dave madden @ 1998-06-11 17:06 UTC (permalink / raw)
To: gyurika@prolan.hu; +Cc: pgsql-sql
=>From: Lendvary Gyorgy <gyurika@prolan.hu>
=>...
=>PQexec(conn, "BEGIN");
=>for (i=0; i<10000; i++)
=>{
=> sprintf(buff, "UPDATE boci SET col3 = %f WHERE row_number=%d",
=>array[i], i);
=> PQexec(conn, buff);
=>}
=>PQexec(conn, "END");
=>
=>This program is very, very slow.
The first thing I'd check is that you have an index on
boci(row_number). If you do, or if adding one doesn't help, then
perhaps you could split boci into two tables:
boci1( row_number int, col2 float )
boci2( row_number int, col3 float )
Then you could use the COPY command to load data from your array. To
select things, just join boci1 and boci2 on row_number (or create a
view, if PostgreSQL supports 'em).
d.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1998-06-11 17:06 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-06-11 08:16 update by one transaction Lendvary Gyorgy <gyurika@prolan.hu>
1998-06-11 08:54 ` Aleksey Dashevsky <postgres@luckynet.co.il>
1998-06-11 13:26 update by one transaction Lendvary Gyorgy <gyurika@prolan.hu>
1998-06-11 17:06 ` dave madden <dhm@paradigm.webvision.com>
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