| From: | "Florian G(dot) Pflug" <fgp(at)phlo(dot)org> |
|---|---|
| To: | emilu(at)encs(dot)concordia(dot)ca |
| Cc: | Bruno Wolff III <bruno(at)wolff(dot)to>, pgsql-general(at)postgresql(dot)org |
| Subject: | Re: in Pl/PgSQL, do commit every 5000 records |
| Date: | 2006-03-10 17:18:28 |
| Message-ID: | 4411B4E4.902@phlo.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Emi Lu wrote:
> The example I have is:
>
> CREATE OR REPLACE function test() returns boolean AS $$
> DECLARE
> ... ...
> counter INTEGER := 0;
> BEGIN
> ... ...
> query_value := ' .....' ;
> OPEN curs1 FOR EXECUTE query_value;
> LOOP
> FETCH curs1 INTO studid;
> EXIT WHEN NOT FOUND;
>
> query_value := ' INSERT INTO ... ...';
> EXECUTE query_value ;
>
> counter := counter + 1 ;
> IF counter%5000 = 0 THEN
> counter := 0;
> COMMIT;
> END IF;
>
> END LOOP;
>
>
> CLOSE curs1; ...
> END;
Are you aware of the "insert into <table> (<field1>, ..., <fieldn>) select <val1>, .., <valn> from ...."
command? It'd be much faster to use that it it's possible...
greetings, Florian Pflug
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Emi Lu | 2006-03-10 17:55:28 | Re: in Pl/PgSQL, do commit every 5000 records |
| Previous Message | Emi Lu | 2006-03-10 17:12:51 | Re: in Pl/PgSQL, do commit every 5000 records |