postgrest-js icon indicating copy to clipboard operation
postgrest-js copied to clipboard

`URI too long` error when supplying a sufficiently large filter

Open kevinschaich opened this issue 2 years ago • 13 comments

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

kevinschaich avatar Jan 23 '23 09:01 kevinschaich

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.

steve-chavez avatar Jan 25 '23 17:01 steve-chavez

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.

Micka33 avatar Sep 08 '23 08:09 Micka33

Seeing this on the flutter web side.

MichealReed avatar Nov 05 '23 14:11 MichealReed

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

bragagia avatar Nov 06 '23 16:11 bragagia

Seeing this issue too when attempting to query 1000 entries

heyaware avatar Jan 08 '24 19:01 heyaware

Issue happening over here on Flutter also when querying more than 200 GUIDs using IN filter.

const response = await supabase
      .from('products')
      .select('*, supplier(*)')
      .not('id', 'in', excludingIds)
      ....

As a side-problem, with RPC (without the Supabase magic) can't seem to find a way to easily obtain joined tables (e.g. supplier) like we do with .select('*, supplier(*)'). If you have any suggestions on how this is done without breaking the standard let me know.

Would like to receive an update on this as it is quite annoying not having the code in one place. Thank you.

rovercoder avatar Feb 02 '24 13:02 rovercoder

@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.

steve-chavez avatar Feb 02 '24 15:02 steve-chavez

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

danielvoelk avatar Apr 14 '24 04:04 danielvoelk

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.

Cali93 avatar Jul 16 '24 10:07 Cali93

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.

didier avatar Aug 25 '24 14:08 didier