[GENERAL] Function with limit and offset - PostgreSQL 9.3 - Mailing list pgsql-general

From marcinha rocha
Subject [GENERAL] Function with limit and offset - PostgreSQL 9.3
Date
Msg-id CY1PR18MB0490632A9A73E64973F66D6BAFCE0@CY1PR18MB0490.namprd18.prod.outlook.com
Whole thread Raw
Responses Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3
Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3
List pgsql-general

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

pgsql-general by date:

Previous
From: Éric
Date:
Subject: Re: [GENERAL] Performance issue with Pointcloud extension
Next
From: "David G. Johnston"
Date:
Subject: Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3