supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
1.04k stars 133 forks source link

Unable to delete multiple records #362

Closed Alexnortung closed 1 year ago

Alexnortung commented 1 year ago

Bug report

Describe the bug

It seems that it is not possible to delete multiple records with the supabase client.

In my project I have a table called public.venue_access with a composite primary key (user_id, venue_id) and my own users table with extra information public.users. I want to set which venues the user can alter in the venue access table. I want to it like in the following example.

supabase.from('venue_access').upsert([{user_id: 1, venue_id: 5}, {user_id: 1, venue_id: 6}])
supabase.from('venue_access').delete().eq('user_id', 1).neq('venue_id', [1,2,3]);

The upsert part work perfectly and inserts the missing records. However the delete part fails and I get the following error

{
  "code":"22P02",
  "details":null,
  "hint":null,
  "message":"invalid input syntax for type bigint: \"1,2,3\""
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a user table with it's id as int8
  2. create a venue access table like descibed above
  3. Create some entries in both tables
  4. run the code in the example

Expected behavior

I expected the records to be deleted with no errors.

Screenshots

Not relavant

System information

Additional context

The http request is:

DELETE http://localhost:54321/rest/v1/venue_access?user_id=eq.1&venue_id=neq.1,2,3
steve-chavez commented 1 year ago

supabase.from('venue_access').delete().eq('user_id', 1).neq('venue_id', [1,2,3]);

Try using in with not instead of neq.

{ "code":"22P02", "details":null, "hint":null, "message":"invalid input syntax for type bigint: \"1,2,3\"" }

The error is telling that you can't compare with equality a bigint with a bigint array.

Alexnortung commented 1 year ago

Thanks alot this works. I solved it by

supabase.from('venue_access').delete().eq('user_id', 1).not('venue_id', 'in', `(${[1,2,3].join(',')})`);

Sorry I reported it as a bug, I guess the error description just didn't make sense to me