VibeCPR

← All fixes

Supabase · supabase-js · PostgREST

Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps

Updated · Applies to: Supabase, Lovable, Bolt, Cursor, v0, Replit, Claude Code

TL;DR fix: Supabase's Data API (PostgREST) returns at most 1,000 rows per request by default, set by Max rows in your project's API settings. Past that it doesn't error: .select() just hands back the first 1,000 with HTTP 200, and .limit(5000) or .range(0, 4999) can't go above the cap. Fix: get the real total with select('*', { count: 'exact', head: true }); for lists, page with .order('id').range(from, from + 999) (page size no bigger than max rows) or keyset pagination (.gt('id', lastId)); for totals and dashboards, compute them in the database with an RPC or view so one row comes back. Don't set max rows to a huge number, and don't switch to the service_role key: it bypasses RLS and is still capped.

Steps

  1. Confirm it's the cap, not missing data. Run the same query with { count: 'exact' }. If data.length is exactly 1,000 (or your max rows value) and count is higher, the API truncated the response. Run select count(*) in the SQL editor to compare.
  2. Find every query that assumes it gets all rows. Search the code for .select( calls that have no .range(), .limit() or .single(), especially ones followed by .length, .reduce(, .filter( or a CSV export. Each is a silent bug once the table passes 1,000 rows.
  3. Replace counts and totals with database-side queries. Use select('*', { count: 'exact', head: true }) for counts, and an RPC function or security_invoker view for sums, averages and per-day stats, so the database returns one row instead of shipping every row to the browser.
  4. Page lists with range() and a stable order. Add .order('id') (or another unique column, or a tie-breaker) and fetch .range(from, from + pageSize - 1) with pageSize no larger than max rows. For 'load everything' loops, stop on an empty or short page, never on a page size above the cap.
  5. Use keyset pagination for big or changing tables. Instead of offsets, fetch .gt('id', lastId).order('id').limit(1000). It doesn't skip or repeat rows when new rows arrive, and stays fast deep into the table.
  6. Leave max rows alone (or raise it a little) and keep RLS on. Max rows protects you from giant accidental or malicious responses for every table and every role, anon included. Keep it low, keep RLS on, and never move a browser query to the service_role or secret key to get more rows.

What it looks like

Nothing errors. The app just looks a bit wrong once a table passes 1,000 rows:

  • The admin “Users” page lists 1,000 users, and new signups never show up.
  • “Total revenue” or “orders this month” stops growing, or is lower than Stripe says.
  • A CSV export has exactly 1,000 lines.
  • Search or filtering done in the browser can’t find rows you can see in the Table Editor.
  • data.length is 1,000 no matter what you pass to .limit().

In the browser’s network tab the request to /rest/v1/your_table returns 200 OK with a Content-Range: 0-999/* header. That 999 is the giveaway.

Why it happens

Supabase’s Data API is PostgREST. PostgREST’s db-max-rows setting is “a hard limit to the number of rows PostgREST will fetch from a view, table, or function”, there to limit the payload of accidental or malicious requests. Plain PostgREST has no limit by default. Supabase’s JS reference says: “By default, Supabase projects return a maximum of 1,000 rows. This setting can be changed in your project’s API settings.” It recommends keeping it low and paging with range().

AI builders write const { data } = await supabase.from('orders').select('*') and then count, sum or filter data in the browser. That works in testing with 40 rows and goes quietly wrong at 1,001.

Things we confirmed against a real PostgREST 16.6 with max rows set to 1,000, called from supabase-js 2.119.2 (details in what we verified):

  • A plain select() on a 2,500-row table returned 1,000 rows, error: null, HTTP 200.
  • .limit(5000) and .range(0, 4999) also returned 1,000. You can ask for fewer than the cap, never more.
  • A set-returning RPC (returns setof posts) is capped too: 1,000 rows. A function or view that returns one row of totals is not affected.
  • The service_role key is capped too (1,000 rows), and on top of that it skips RLS.

Step 1: the 2-minute check

In the browser console of your app (or a test script), compare what you get with the real count:

const { data, count, error } = await supabase
  .from('orders')
  .select('id', { count: 'exact' })
console.log({ rows: data?.length, count, error })
// { rows: 1000, count: 2500, error: null }  <- truncated by max rows

Supabase’s reference notes that with count, the number is the total matching your filters, not the size of the page, which is exactly the comparison you want. Then find every query that assumes it got everything:

# selects with no range/limit/single on the same line (rough: multi-line chains need a look)
grep -rnE "\.select\(" src | grep -vE "range\(|limit\(|single\(|maybeSingle\(|head: ?true"
# code that sums/counts/filters in the browser after a select
grep -rnE "data\??\.(length|reduce|filter)\b" src

Anything that feeds a total, a count, an export or an admin list is a bug once the table grows.

What you seeCauseFix
Exactly 1,000 rows, no errorMax rows cap on a plain select()Count / page
.limit(5000) still gives 1,000limit can’t go above max rowsPage or aggregate
“Load all” loop stops at 1,000Page size bigger than max rows, loop stops on a “short” pagePage size ≤ max rows (Fix B)
Duplicate or missing rows across pagesNo order, or offset paging while rows are addedUnique order + keyset
Revenue / totals too lowSumming a truncated array in the browserRPC or view
Admin page missing usersListing a 1,000+ row table in one requestPage + server-side search
count: 'estimated' is offEstimated is only exact below max rowsUse count: 'exact'
Fewer rows than count(*) in the SQL editor, even after pagingRLS: the user only sees their rows (correct)Nothing; or check your SELECT policy
PGRST116 from .single()Different problem: 0 or 2+ rowsThat fix

Fix A: count without fetching rows

const { count, error } = await supabase
  .from('profiles')
  .select('*', { count: 'exact', head: true })

head: true returns no rows, only the count, so the cap doesn’t matter (we got 2,500 for 2,500 rows). Two notes from PostgREST’s pagination docs: an exact count gets slower as the table grows, and estimated returns the exact count only up to the max rows threshold, then switches to Postgres’ planner estimate. In our test count: 'estimated' said 2,033 for a 2,500-row table, so don’t show it as “Total users”.

Fix B: page with range() and a stable order

For a list screen, fetch one page at a time and use the count for the page links:

const PAGE = 50
const { data, count, error } = await supabase
  .from('orders')
  .select('id, created_at, amount', { count: 'exact' })
  .order('created_at', { ascending: false })
  .order('id', { ascending: false })   // tie-breaker: makes the order unique
  .range(page * PAGE, page * PAGE + PAGE - 1)

range(from, to) is 0-based and inclusive, and Supabase’s docs warn that without an order “the range could behave unexpectedly”. Postgres’ docs are blunter: without an ORDER BY that makes the order unique, LIMIT/OFFSET give “an unpredictable subset” and different pages can overlap.

When you really need every row (an export, a sync job), loop, with a page size no bigger than max rows:

async function fetchAll(table, columns = '*', pageSize = 1000) {
  const rows = []
  for (let from = 0; ; from += pageSize) {
    const { data, error } = await supabase
      .from(table).select(columns)
      .order('id')                                   // unique, stable
      .range(from, from + pageSize - 1)
    if (error) throw error                           // don't return a partial list as if it were complete
    rows.push(...data)
    if (data.length < pageSize) break                // short page = last page
  }
  return rows
}

The trap we hit on purpose: with pageSize = 5000, the first page came back with 1,000 rows, the loop saw “fewer than 5,000, must be the end” and stopped. Same silent truncation, now inside your fix. Keep pageSize ≤ max rows (1,000 by default) or stop only on an empty page.

Fix C: keyset pagination

Offset paging re-counts from the top every time. If new rows arrive between pages of a newest-first list, everything shifts down: in our test, 10 inserts between page 1 and page 2 put 10 duplicates on page 2 (and pushed 10 rows off the end). Large offsets also get slower, because Postgres still computes the skipped rows. Keyset pagination asks for “the next rows after the last one I saw”:

let lastId = 0
const all = []
while (true) {
  const { data, error } = await supabase
    .from('posts').select('id, title')
    .gt('id', lastId)
    .order('id')
    .limit(1000)
  if (error) throw error
  all.push(...data)
  if (data.length < 1000) break
  lastId = data[data.length - 1].id
}

That returned all 2,510 rows once each after the inserts. It works on any unique, sortable column, including a random uuid primary key (the order won’t be chronological, but nothing is skipped or repeated). Index the column you page on.

Fix D: totals and dashboards in the database

Don’t download 50,000 rows to show one number. Return the number:

create or replace function public.my_order_totals()
returns table (order_count bigint, total numeric)
language sql stable
security invoker            -- runs as the caller, so RLS on orders still applies
set search_path = ''
as $$
  select count(*), coalesce(sum(amount), 0) from public.orders
$$;
revoke execute on function public.my_order_totals() from public, anon;
grant execute on function public.my_order_totals() to authenticated;
const { data, error } = await supabase.rpc('my_order_totals')
// [{ order_count: 2300, total: 115000 }]

In our test, summing the same user’s orders in the browser after a plain select() gave 1,000 rows and 50,000; the RPC gave 2,300 orders and 115,000. A view with with (security_invoker = true) that returns one row of stats works the same way (see views that bypass RLS before creating one). Group by day or status in the function if the chart needs one row per bucket.

PostgREST also has built-in aggregates (select=amount.sum()), but its docs say they are disabled by default because they can cause performance problems. We didn’t check whether they’re turned on for Supabase projects, so we don’t rely on them here.

For “search all users” on an admin page, filter in the query (.ilike('email', '%' + q + '%'), paged) instead of loading everyone and filtering in the browser.

Raising Max rows: when and how much

You can change Max rows in your project’s API settings (Supabase’s docs link to Project Settings → API; we didn’t test the dashboard). With our local PostgREST at 3,000, a plain select returned all 2,510 rows. Why not set it to 100,000 and move on:

  • It applies to every table and every role, anon included. Anyone with your public key can download that many rows per request from any table their policies let them read. PostgREST describes the setting as a limit on payload size for accidental or malicious requests.
  • It only moves the cliff. Your code still breaks silently at the new number, just later, when it’s harder to notice.
  • Big responses are slow on the database, the network and the user’s phone.

If one screen genuinely needs, say, 2,000 rows at once, a modest bump is fine. Everything else should page or aggregate.

Security: don’t fix it by widening access

  • RLS still applies to paging and counts. In our test the signed-in user paged through exactly her 2,300 orders (0 rows from anyone else), another user got his 50, and anon got permission denied. That’s correct. If paging gives a user fewer rows than count(*) in the SQL editor, RLS is working, not the cap.
  • Don’t switch to the service_role / secret key to get “all the rows”. Our service_role-style token still got 1,000 rows, and its count was 2,350, every user’s orders. The key bypasses RLS and must never be in browser code. If the agent already did this, see RLS not working because the server uses the service_role key.
  • Don’t widen a policy to using (true) so an admin page can list everyone. Give admins their own policy or a security definer function in a private schema (see the RLS recursion fix for the safe pattern).
  • Keep RPCs security invoker unless you mean otherwise, and revoke EXECUTE from anon if signed-out users shouldn’t call them. A security definer totals function owned by postgres skips RLS and sums everyone’s rows for every caller (why).

Paste this into Lovable, Bolt, Cursor or Claude Code

Our Supabase tables have more than 1,000 rows and the Data API returns at most 1,000 rows
per request (Max rows), silently. Fix every place that assumes a select() returns all rows:

1. Find every supabase .select() without .range()/.limit()/.single()/head:true, and every
   place that uses data.length, .reduce or .filter on the result for counts, totals,
   exports, search or admin lists. List them before changing anything.
2. Counts: use .select('*', { count: 'exact', head: true }). Don't use count 'estimated'.
3. Totals/charts: write a Postgres function (security invoker, set search_path = '',
   revoke execute from public and anon, grant to authenticated) that returns the aggregate
   rows, and call it with supabase.rpc(). Show me the SQL first.
4. Lists: page with .order(<unique column>) (add id as a tie-breaker) and .range(), page size
   <= 1000, using the count for page links. Search/filter in the query, not in the browser.
5. "Fetch everything" (exports, sync): keyset pagination with .gt('id', lastId).order('id')
   .limit(1000), throw on error, stop on a short page.
6. Do NOT raise Max rows to a big number, do NOT use the service_role/secret key in the
   browser, and do NOT loosen any RLS policy to make this work.
7. Give me a test: with a table of 2,500 rows, each fixed screen shows the right count/total.

What we verified

  • Tested locally (Nov 25, 2026; PostgreSQL 17.12 throwaway cluster + PostgREST 16.6 with db-max-rows=1000, supabase-js 2.119.2 createClient() through a small proxy that maps /rest/v1; Supabase-style anon, authenticated and a BYPASSRLS service_role role, auth.uid() reading request.jwt.claims; research/max-rows-test/run.sh, output run.out.txt):
    • Plain select(), .limit(5000) and .range(0, 4999) on 2,500 rows: 1,000 rows each, error: null, HTTP 200, Content-Range: 0-999/*.
    • count: 'exact', head: true: 2,500. select with count: 'exact': 1,000 rows, count 2,500. count: 'estimated': 2,033 (table not analyzed).
    • range() loop ordered by id: all 2,500 rows, no duplicates, with pages of 1,000 (3 requests) and 500 (6). Page size 5,000: stopped after 1 page with 1,000 rows.
    • Offset paging newest-first with 10 inserts between pages: 10 duplicates on page 2. Keyset paging: 2,510 unique rows.
    • RLS: 2,300 / 50 rows for the two users, none of each other’s; anon permission denied. Browser-side sum over a plain select: 1,000 rows, 50,000; security invoker RPC: 2,300 and 115,000; anon got 42501 on the RPC. A setof RPC was capped at 1,000; a one-row security_invoker view was correct.
    • service_role-style token: 1,000 rows, count 2,350 (all users).
    • Max rows raised to 3,000: plain select returned 2,510 rows.
  • Docs-based, not tested on a real Supabase project (sources below, fetched Nov 25, 2026, all HTTP 200; list in research/max-rows-2026-11-25.md): the 1,000-row default on Supabase and where the Max rows setting lives in the dashboard, Supabase’s advice to keep it low, the slowdown of exact counts on very large tables, PostgREST aggregates being off by default, large offsets being inefficient. We did not check Supabase’s upper limit for Max rows or whether a change needs a restart.
  • Our reading, not documented: that AI builders often generate unpaged select() calls and browser-side totals.

Related: .single() “JSON object requested, multiple (or no) rows returned”, form says success but no row in Supabase, RLS not working because the server uses the service_role key, views that bypass RLS, and check your RLS in two minutes.

When to get help

Get help if your admin dashboard, billing totals or exports have been wrong for a while and you need to know which numbers to trust, if your agent 'fixed' it by moving queries to the service_role key, or if you need reporting that won't fall over as the tables grow.

FAQ

Why does Supabase only return 1,000 rows?

Supabase's Data API is PostgREST, and Supabase projects cap each response at 1,000 rows by default (the Max rows setting in your project's API settings). Supabase's docs say to keep it low to limit the payload size of accidental or malicious requests, and to use range() to paginate. The cut is silent: in our test the request returned HTTP 200, error null and exactly 1,000 of 2,500 rows.

Does .limit(5000) or .range(0, 4999) get around the 1,000-row limit?

No. Max rows is a hard limit on the server. In our test with PostgREST and max rows at 1,000, both .limit(5000) and .range(0, 4999) returned 1,000 rows with no error. A client can ask for fewer rows than the cap, never more.

How do I count all rows in a Supabase table without hitting the 1,000-row limit?

Use supabase.from('table').select('*', { count: 'exact', head: true }). It returns only the count, not rows, so the cap doesn't apply: we got 2,500 for a 2,500-row table. Counting data.length after a plain select gave 1,000. Exact counts get slower on very large tables. count: 'estimated' is only exact below the max rows threshold: it gave us 2,033 for 2,500 rows.

How do I fetch all rows from Supabase with range()?

Loop .range(from, from + pageSize - 1) with a stable .order() on a unique column and a page size no larger than max rows, and stop when a page comes back short. In our test, pages of 1,000 returned all 2,500 rows. The same loop with a page size of 5,000 stopped after one page with 1,000 rows, because the first page was already "short".

Should I just raise Max rows in Supabase?

Only a little, and only if a screen truly needs it. The setting applies to every table and every role, including anon, so a big value lets anyone with your public key pull that many rows from any table they can read in one request, and makes accidental full-table loads slow. Page or aggregate in the database instead.

Will the service_role key return more than 1,000 rows?

No. In our test a service_role-style token still got 1,000 rows. It also bypassed RLS: its count was 2,350, every user's orders, against 2,300 for the signed-in user. Swapping keys doesn't lift the cap, it leaks other users' data, and the secret key must never be in browser code.

Why are my dashboard totals wrong in Supabase but there is no error?

Your code probably sums or counts the rows a plain select() returned, which stops at 1,000. In our test, summing a user's 2,300 orders in the browser gave 50,000 instead of 115,000. Compute totals in the database with an RPC function or view that returns one row, and count with count: 'exact', head: true.

Sources

Related fixes