supabase-py
supabase-py copied to clipboard
How do I add multiple filters to my query?
Hello,
I am trying to query a table by adding multiple filters in the following manner:
supabase_client.table("table").select("*").eq('col1', value1).lte('col2', value2).lte('col3', value3).execute()['data']
I do not get any data returned despite there being data available that passes all the conditions. If I just use one filter, then data is returned perfectly fine
Hi, apologies for the late response.
Note that when you chain multiple filters as you have done in your example, the effect is that they are joined with an AND, i.e col1 = value1 AND col2 <= value2 .... Are you sure that data which matches all of those filters exist?
If so, can you upgrade to the latest version of supabase-py and see if the error persists?
PS: in the newer versions, the query response isn't subscriptable as the .execute() method returns an instance of APIResponse, so you'd do
res = supabase_client.table("table").select("*").eq('col1', value1).lte('col2', value2).lte('col3', value3).execute()
res.data # the data returned by the query
Hey @anand2312 - sorry for the late reply! I did try this just now:
supabase_client.table("carrier_bill_data").select("*").eq(col1, val1).eq(col2, val2).neq(col3, val3).execute()
I'm trying to find values that match condition 1 and condition 2 but not condition 3. It seems to be working with the 2 eq clauses, but when I add the neq clause, it does not return any data despite there being data that matches all conditions. I'm using the latest version of supabase
Hmm, that's very odd. I am not able to reproduce this.
Quickly tried this:

Queried similar to what you have shown:
In [8]: r = client.from_("example").select("*").eq("foo", 1).eq("bar", "helloworld").neq("baz", "not supabase").execute()
In [9]: r.data
Out[9]:
[{'id': 1,
'created_at': '2022-05-10T07:35:21+00:00',
'foo': 1,
'bar': 'helloworld',
'baz': 'supabase'}]
and it matches the first row as expected (it is the only row that has both foo = 1 and bar = helloworld, and it has baz != "not supabase")
Can you give some more context possibly that could help me reproduce this? @mohnish7
Also if possible, enable debug logging as described here https://postgrest-py.readthedocs.io/en/latest/examples/logging.html and send that output as well (after removing your API URL) Sorry I'm not able to get back to your questions fast enough 😅
Hey @mohnish7,
Sorry for the delayed response - can I check if this is still an issue?
Jo
@J0 this is not an issue anymore and I haven't been able to reproduce it. the ticket can be closed