sql - Looping through relational table -


is possible loop through postgres while changing values of limit , offset. want loop through till end of relational table reached. reason want dynamically set limit , offset have little virtual memory of 1 gb due process getting killed.

currently approach taking manually set values of limit , offset.

select *  my_relational_table limit 1000 offset 0; select *  my_relational_table limit 1000 offset 1000; select *  my_relational_table limit 1000 offset 2000; 

is possible automate process within postgres such loop stops when end of relational table reached.

yes, possible. can use cursor , command fetch.

example:

postgres=# begin read only; begin postgres=# declare xx cursor select * generate_series(1,100); declare cursor postgres=# fetch 2 xx;  generate_series  -----------------                1                2 (2 rows)  postgres=# fetch 2 xx;  generate_series  -----------------                3                4 (2 rows)  postgres=# fetch 2 xx;  generate_series  -----------------                5                6 (2 rows)  postgres=# fetch 2 xx;  generate_series  -----------------                7                8 (2 rows)  postgres=# commit; commit 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -