postgrest-js: `URI too long` error when supplying a sufficiently large filter

Bug report

Describe the bug

GET request fails on large queries

To Reproduce

async function getData(table: string, objectIds: string[], limit: number): Promise<Object[]> {
    const data = await supabase.from(table).select('*').limit(limit).in('id', objectIds)
    return data
}

Run with more than ~10-15 object IDs and it fails because the URL becomes too long for a GET request.

Expected behavior

If the URL exceeds a certain length, this should be submitted as a POST request instead, with the IDs in the body of the request

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 18
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Any fix coming for this that doesn’t rely on us batching 200 UUID’s at a time? I really feel like this should be handled in the library and not devs making faulty middleware. The problem is bigger than just having to batch too. I have an issue where I want to query the count of a table with a large list. The only way to do this now is two sets of batch requests.

This seems like a high priority bug to fix. I’m doing a filter on some data and want to do it via Supabase (or rather, in SQL, as opposed to JavaScript, for performance reasons). It should be possible to fallback to a different format and not be limited by URI length.

EDIT: It’s not necessarily a bug, but it is something you’d expect to work without hiccup.

Using an RPC method is not an option in our case because we’re building our query dynamically based on some conditions and writing the whole logic as a Postgres function isn’t a viable option.

Linking https://github.com/PostgREST/postgrest/issues/2125.

If the URL exceeds a certain length, this should be submitted as a POST request instead, with the IDs in the body of the request

Planning to use the HTTP SEARCH method instead.

For now you can workaround this with rpc() as described here, example here.

I ended up solving this issue with an rpc but it’s far from ideal (rpcs are a mess, hard to read and maintain)

I have the same issue. Is it possible to do a normal select query as a POST request?

Same here, I have to batch my updates in order to avoid this issue which is pretty annoying.

Seems like this still hasn’t been fixed. I’m also using the batching solution for now, but it’s obviously slower than I’d like. Really should be addressed soon.

@rovercoder If your RPC is defined as CREATE FUNCTION func ... RETURNS SETOF PRODUCTS then you can use rpc(func).select('*, supplier(*)'), the same as for tables.

I have the same issue.

    const response = await supabase
      .from('team_profile')
      .select('id, team_id, profile!inner( identifier )')
      .in('profile.identifier', identifiers)
      .eq('team_id', teamId);

if identifiers are too many, or if they are too long, this will triggers Error: URI too long. Because this code generate a get request, and it exceeds the maximum URI Length accepted by the server.