How would I do a pop on a PG::Result in Ruby? -


running pop on result set pgsql database get:

undefined method `pop' #<pg::result:0x0000000273dc08> 

i want first 5 of result set, it, again next 5. don't want run query twice long query.

how in ruby?

i running ruby 2.1 , rails 3.0.

pg::result enumerable use each_slice on it:

your_pg_result.each_slice(5) |array|   # array @ 5 rows result set   # on each iteration whatever needs done end 

if need differentiate iterations throw with_index mix:

your_pg_result.each_slice(5).with_index |array, i|   # ... end 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -