supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
967 stars 130 forks source link

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

Open kevinschaich opened 1 year ago

kevinschaich commented 1 year ago

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

steve-chavez commented 1 year ago

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.

Micka33 commented 10 months ago

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.

MichealReed commented 8 months ago

Seeing this on the flutter web side.

bragagia commented 8 months ago

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

heyaware commented 5 months ago

Seeing this issue too when attempting to query 1000 entries

rovercoder commented 5 months ago

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.

steve-chavez commented 5 months ago

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

danielvoelk commented 2 months ago

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