Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread John R Pierce
On 6/8/2017 6:36 PM, marcinha rocha wrote: |UPDATEtablea a SETmigrated =yes WHEREa.id =row.id;| On my original select, the row will have migrated = false. Maybe All I need to put is a limit 2000 and the query will do the rest? SELECT does not return data in any determinate order unless you

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread David G. Johnston
On Thursday, June 8, 2017, marcinha rocha wrote: > On Thursday, June 8, 2017, marcinha rocha hotmail.com > > > wrote: > >> On my original select, the row will have

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread marcinha rocha
On Thursday, June 8, 2017, marcinha rocha > wrote: On my original select, the row will have migrated = false. Maybe All I need to put is a limit 2000 and the query will do the rest? You shoud try to avoid the for

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread David G. Johnston
On Thursday, June 8, 2017, marcinha rocha wrote: > On my original select, the row will have migrated = false. Maybe All I > need to put is a limit 2000 and the query will do the rest? > > You shoud try to avoid the for loop, but yes a limit 2000 on the for loop

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread marcinha rocha
On 6/8/2017 5:53 PM, marcinha rocha wrote: > 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. I'm sure your example is a gross simplification of what you're really doing, but if that's really all

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread John R Pierce
On 6/8/2017 5:53 PM, marcinha rocha wrote: 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. I'm sure your example is a gross simplification of what you're really doing, but if that's really all

Re: [GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread David G. Johnston
On Thursday, June 8, 2017, marcinha rocha wrote: > 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 > > You can do this is with plain sql with the help of a CTE. Insert

[GENERAL] Function with limit and offset - PostgreSQL 9.3

2017-06-08 Thread marcinha rocha
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