🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Database / Supabase RLS

Supabase only returns 1,000 rows (max rows limit)

LovableBoltCursorReplitv0

Published

The error

My Supabase select returns exactly 1000 rows but the table has more / .limit(5000) still gives me 1000 rows / CSV export or admin table is missing the newest records / totals and charts are wrong once the table passes 1,000 rows / data.length is 1000 but the dashboard row count is higher / the response header shows Content-Range: 0-999/* / an rpc() call that returns a set of rows also stops at 1000

Why it happens

Supabase's Data API (PostgREST) has a hard cap on how many rows one request can return. Supabase's docs say projects return a maximum of 1,000 rows by default, and the CLI config describes the same api.max_rows setting as the maximum number of rows returned from a view, table or function. When a query matches more rows than that, you get the first 1,000 and no error, so nothing looks broken until someone notices missing records. Asking for more with .limit(5000) does not help, because PostgREST treats max rows as a hard limit. AI builders hit this in three common ways: a list, table or export loads everything with one select() and no paging; the app computes totals, sums or charts in JavaScript from data.length or a loop over the result, so the numbers silently stop at 1,000 rows; or a Postgres function called with rpc() returns a set of rows, which is capped the same way. Supabase recommends keeping the limit low to limit the size of accidental or malicious requests, and paginating with range().

How to fix it

  1. Confirm it is the row cap. Run the same filter as a count in the SQL editor (select count(*) from your_table where ...) and compare it with data.length in the app. If the app shows exactly 1,000 (or whatever your Max rows setting is) while the count is higher, this is the cause. In DevTools > Network you can also open the request to /rest/v1/your_table and look at the Content-Range response header: 0-999/* means the first 1,000 rows were returned.
  2. Page through large lists instead of loading everything. Use range(from, to), which Supabase documents as 0-based and inclusive, so range(0, 49) is the first 50 rows and range(50, 99) the next 50. Always add an order() on a unique column such as id or created_at plus id, because Supabase warns that range without an order clause can behave unexpectedly and rows can repeat or go missing between pages.
  3. Show the real total. Ask Supabase for the count instead of using data.length: select('*', { count: 'exact', head: true }) returns only the count, and adding count to a range() query returns the total number of matching rows, not the page size. On very large tables 'exact' runs a full COUNT(*) and gets slow; supabase-js also accepts 'planned' (fast estimate from Postgres statistics) and 'estimated' (exact for small numbers, planned for large ones).
  4. Fix exports and background jobs that need every row. Loop: fetch range(0, 999), then range(1000, 1999) and so on, ordered by id, until a page comes back with fewer rows than you asked for. For big tables, page by the last id instead of an offset: .gt('id', lastId).order('id').limit(1000). Run large exports on the server (an API route or Edge Function) rather than in the browser.
  5. Move totals, sums and charts into the database. Instead of downloading rows to add them up in JavaScript, write a Postgres function that returns the single number or the small grouped result (for example select sum(amount) ... group by month) and call it with supabase.rpc(). A function that returns one row is not affected by the cap, and RLS still applies if the function is not security definer.
  6. Fix rpc() calls that return many rows. Max rows applies to functions too. Add paging inside the function (limit and offset parameters), or chain range() and order() on the rpc() call for set-returning functions, the same way as for a table.
  7. Only raise Max rows if you really need to, and know the trade-off. It is a project setting in the Supabase dashboard's Data API / API settings (api.max_rows in supabase/config.toml for local development). Supabase recommends keeping it low, because every query without paging gets heavier and anyone with your public key can pull more rows per request. Paging is the real fix; raising the cap only moves the cliff.
  8. Test with more than 1,000 rows. Seed a test project or branch with a few thousand rows and check every list, search, export, total and chart. Add an automated check that the count shown in the UI matches select count(*) for the same filter.

Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

Bug: my Supabase queries stop at 1,000 rows with no error, so lists, exports and totals are missing data. Fix it properly without just raising the Max rows setting. 1) Find every supabase.from(...).select(...) and supabase.rpc(...) call that can return more than 1,000 rows, and every place that uses data.length or loops over results to compute a total, sum or chart. 2) For lists and tables, add server-friendly pagination with .range(from, to) and an .order() on a unique column (id), plus a total from select('*', { count: 'exact', head: true }) or count: 'estimated' for very large tables. 3) For exports, write a loop (preferably in an API route or Edge Function) that fetches pages of 1,000 ordered by id until a page is shorter than the page size. 4) Replace totals and charts computed in JavaScript with a Postgres function that returns the aggregated result, called with supabase.rpc(); keep RLS working (no security definer unless needed and reviewed). 5) Do not disable RLS and do not use the service_role key in the browser. 6) Seed more than 1,000 test rows and show me that the UI counts match select count(*). Show the code and SQL diffs.

Error codes this fixes

FAQ

Why does Supabase only return 1,000 rows?

Supabase's Data API caps every request at a maximum number of rows, 1,000 by default, to limit the payload of accidental or malicious requests. Queries that match more rows return only the first 1,000 and no error. Use range() to page through the rest.

Why doesn't .limit(5000) return 5,000 rows from Supabase?

Max rows is a hard limit on what PostgREST will return for a table, view or function. limit() can ask for fewer rows than the cap, but not more. Page with range() instead.

How do I get the total row count in Supabase?

Use the count option: select('*', { count: 'exact', head: true }) returns only the count. With range() it returns the total number of matching rows, not the size of the page. Use 'planned' or 'estimated' on very large tables where an exact count is slow.

Should I just increase Max rows in Supabase?

Usually not. Supabase recommends keeping it low. A higher cap makes every unpaged query heavier and lets anyone with your public key download more rows per request. Paginate lists and do totals in the database instead.

Does the 1,000 row limit apply to rpc functions?

Yes. The setting is the maximum number of rows returned from a view, table or function. Page inside the function or chain range() and order() on the rpc() call, or return an aggregated result instead of raw rows.

Why do my paginated Supabase results repeat or skip rows?

range() without a stable order can return rows in a different order on each request. Add .order('id') (or created_at plus id) so every page is cut from the same sorted list.

Sources

Based on the official documentation:

Related fixes

Want the full checklist for this area? Get a Fix Kit ($29)

Get one new fix a week

Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.

We only use your email to send the newsletter. Unsubscribe any time. See privacy.