Getting doublets of records while using an offset

Consider this schenario where I’m having pagination on a page

@recordings =  Recording.order(:title).page(params[:page]).per(4)
 puts params[:page]
@recordings.each do |recording|
      puts recording.id
end 
  page ----------------3------------------------
Recording Load (4.0ms) SELECT "recordings".* FROM "recordings" ORDER BY "recordings"."title" ASC LIMIT 4 OFFSET 8
1032
952
1063
1166 <<<<<<<<<<<<<<<<<<<<<<<<<< notice 
page ----------------4------------------------
Recording Load (4.3ms) SELECT "recordings".* FROM "recordings" ORDER BY "recordings"."title" ASC LIMIT 4 OFFSET 12
1166 <<<<<<<<<<<<<<<<<<<<<<<<<< notice 1168
657
756
So record 1166 is on both pages

Is the issue that title is not in fact unique?

If so you could order on two columns (rather than creating an extra unique column), for example

Recording.order(:title, :id).page(params[:page]).per(4)

Fred

Are you on Postgresql? It takes a very literal interpretation of the SQL standard when row order isn’t uniquely specified:

Sorting on something that’s reliably unique (even just id along with title) should sort this out.

–Matt Jones