supabase-rb-rb
Database

Limit the query to a range

Inclusive [start, finish] slice. Sets offset and limit in one call.

Select an inclusive row range. Lives on the select (and rpc) builder via SelectMixin. Implemented as a one-call shorthand that sets offset = start and limit = finish - start + 1 on the underlying request.

Signature

builder.range(start, finish, foreign_table: nil)

Parameters

NameTypeRequiredDescription
startIntegerRequiredZero-based index of the first row to include.
finishIntegerRequiredZero-based index of the last row to include (inclusive). The row count returned is finish - start + 1.
foreign_tableStringOptionalApply the range to an embedded resource. Rewrites the keys to <foreign_table>.offset / <foreign_table>.limit.

Returns

Returns
self (SelectRequestBuilder)

The same builder, so you can keep chaining other modifiers / filters before .execute.

Example — first 10 rows

range(0, 9) is inclusive, so it returns 10 rows (indexes 0..9).

response = supabase
  .from("countries")
  .select("id, name")
  .order("id")
  .range(0, 9)
  .execute

response.data.length  # => 10

Example — next page

For a "page 2 of 10-per-page" slice, use range(10, 19).

supabase
  .from("countries")
  .select("id, name")
  .order("id")
  .range(10, 19)
  .execute

Example — range on an embedded resource

supabase
  .from("authors")
  .select("name, books(title)")
  .range(0, 4, foreign_table: "books")
  .execute

On this page