Demo, all content is generated
Question

Supabase only returns 1000 rows even with .limit(5000)

Solved · 1151 views · asked by kai_makes · edited

Exporting all orders to CSV for my accountant. There are about 3400. My code:

const { data } = await supabase.from('orders').select('*').limit(5000)
console.log(data.length) // 1000

No error. Just 1000. Is this a free plan thing?

What I’ve tried

Removed limit, still 1000. Tried .range(0, 4999), still 1000.

Comment
I had the same and thought my import was broken for two days. sunita_d · edited

2 answers

Marked as helpful by the asker
hannah_reyes · edited

Not a plan thing. The API has a Max rows setting (default 1000) that caps every response, regardless of what you ask for. You can raise it under the Data API settings, but for an export I'd paginate instead:

const pageSize = 1000
let all = []
for (let from = 0; ; from += pageSize) {
  const { data, error } = await supabase
    .from('orders').select('*')
    .order('id')
    .range(from, from + pageSize - 1)
  if (error) throw error
  all = all.concat(data)
  if (data.length < pageSize) break
}

The .order() matters, without a stable order pages can overlap or skip rows. Raising the max rows limit for everything also means one careless query can pull your whole table into a browser.

Comment
3412 rows. Thank you!! kai_makes · edited
Or .csv() on the query builder, it returns the result as CSV text. Still subject to the same limit though, so you'd page anyway. bea_quinn · edited
olu_backend · edited

For an accountant export I'd do it on the server anyway (edge function or a route in your app) so you don't pull 3400 rows into someone's phone, and you can stream the CSV straight out.

Comment