Hi guys! I have the following queries, which will basically select data, insert 
it onto a new table and update a column on the original table.


CREATE or REPLACE FUNCTION migrate_data()
RETURNS integer;

declare
        row record;

BEGIN

FOR row IN EXECUTE '
        SELECT
              id
        FROM
              tablea
        WHERE
              mig = true
'
LOOP

INSERT INTO tableb (id)
VALUES (row.id);

UPDATE tablea a SET migrated = yes WHERE a.id = row.id;

END LOOP;

RETURN numrows; -- I want it to return the number of processed rows

END

$$ language 'plpgsql';


When I call the function, it must execute 2000 rows and then stop. Then when 
calling it again, it must start from 2001 to 4000, and so on.


How can I do that? I couldn't find a solution for this..



Thanks!
Marcia

Reply via email to