supabase-rb-rb
Database

Limit the number of rows

Cap the number of rows returned. Optionally limits an embedded resource.

Add a LIMIT to the query. Lives on the select (and rpc) builder via SelectMixin. Calling limit more than once just overwrites the previous value — only the last call sticks.

Signature

builder.limit(size, foreign_table: nil)

Parameters

NameTypeRequiredDescription
sizeIntegerRequiredMaximum number of rows to return.
foreign_tableStringOptionalLimit an embedded resource instead of the parent table. Rewrites the query key to <foreign_table>.limit so PostgREST caps the joined relation.

Returns

Returns
self (SelectRequestBuilder)

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

Example — first 10 rows

response = supabase
  .from("countries")
  .select("id, name")
  .order("name")
  .limit(10)
  .execute

Example — paginate with offset

limit pairs with offset for paging, or use range for a one-call inclusive slice.

supabase
  .from("countries")
  .select("id, name")
  .order("id")
  .offset(20)
  .limit(10)
  .execute

Example — limit an embedded resource

foreign_table: caps the joined relation independently of the parent.

supabase
  .from("authors")
  .select("name, books(title)")
  .limit(5, foreign_table: "books")
  .execute

On this page