[GENERAL] Function with limit and offset - PostgreSQL 9.3
От | marcinha rocha |
---|---|
Тема | [GENERAL] Function with limit and offset - PostgreSQL 9.3 |
Дата | |
Msg-id | CY1PR18MB0490632A9A73E64973F66D6BAFCE0@CY1PR18MB0490.namprd18.prod.outlook.com обсуждение исходный текст |
Ответы |
Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3
Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3 |
Список | 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 по дате отправления: