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.
Implement URLQueryRepresentable protocol in your own types to be able to use them as filter value.
Supported filtes are: eq, neq, gt, gte, lt, lte, like, ilike, is, in, cs, cd, sl, sr, nxl, nxr, adj, ov, fts, plfts, phfts, wfts. Check available operators in PostgREST.
try await supabase
.from("cities")
.select("name, country_id")
.eq("name", value: "The Shire") // Correct
try await supabase
.from("citites")
.eq("name", value: "The Shire") // Incorrect
.select("name, country_id")
try await supabase
.from("cities")
.select("name, country_id")
.gte("population", value: 1000)
.lt("population", value: 10000)
let filterByName: String? = nil
let filterPopLow: Int? = 1000
let filterPopHigh: Int? = 10000
var query = await supabase
.from("cities")
.select("name, country_id")
if let filterByName {
query = query.eq("name", value: filterByName)
}
if let filterPopLow {
query = query.gte("population", value: filterPopLow)
}
if let filterPopHigh {
query = query.lt("population", value: filterPopHigh)
}
struct Response: Decodable {
// expected fields
}
let result: Response = try await query.execute().value
try await supabase
.from("users")
.select()
.eq("address->postcode", value: 90210)
try await supabase
.from("orchestral_sections")
.select(
"""
name,
instruments!inner (
name
)
"""
)
.eq("instruments.name", value: "flute")