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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -