Filters allow you to only return rows that match certain conditions.
Filters can be used on select()
, update()
, upsert()
, and delete()
queries.
If a Postgres function returns a table response, you can also apply filters.
# Correct
response = (
supabase.table("cities")
.select("name, country_id")
.eq("name", "Bali")
.execute()
)
# Incorrect
response = (
supabase.table("cities")
.eq("name", "Bali")
.select("name, country_id")
.execute()
)
response = (
supabase.table("cities")
.select("name, country_id")
.gte("population", 1000)
.lt("population", 10000)
.execute()
)
filterByName = None
filterPopLow = 1000
filterPopHigh = 10000
query = supabase.table("cities").select("name, country_id")
if filterByName:
query = query.eq("name", filterByName)
if filterPopLow:
query = query.gte("population", filterPopLow)
if filterPopHigh:
query = query.lt("population", filterPopHigh)
response = query.execute()
response = (
supabase.table("users")
.select("*")
.eq("address->postcode", 90210)
.execute()
)
response = (
supabase.table("countries")
.select("name, cities!inner(name)")
.eq("cities.name", "Bali")
.execute()
)