Commit every N rows in PL/pgsql - Mailing list pgsql-general

From Len Walter
Subject Commit every N rows in PL/pgsql
Date
Msg-id AANLkTinrqm3pXn-AOoUSKY7s_Xb4If6ajgpQ1bcXATF-@mail.gmail.com
Whole thread Raw
Responses Re: Commit every N rows in PL/pgsql  (Jaime Casanova <jaime@2ndquadrant.com>)
Re: Commit every N rows in PL/pgsql  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Commit every N rows in PL/pgsql  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: Commit every N rows in PL/pgsql  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-general
Hi,

I need to populate a new column in a Postgres 8.3 table. The SQL would be something like "update t set col_c = col_a + col_b". Unfortunately, this table has 110 million rows, so running that query runs out of memory.
In Oracle, I'd turn auto-commit off and write a pl/sql procedure that keeps a counter and commits every 10000 rows (pseudocode):

define cursor curs as select col_a from t
while fetch_from_cursor(curs) into a
     update t set col_c = col_a + col_b where col_a = a
     i++
     if i > 10000
         commit; i=0;
     end if;
     commit;

PL/pgsql doesn't allow that because it doesn't support nested transactions. 
Is there an equivalent Postgres way of doing this?

cheers,

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Transaction with in function
Next
From: Ravi Katkar
Date:
Subject: Re: Transaction with in function