For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.
Filters allow you to only return rows that match certain conditions.
Filters can be used on select(), update(), and delete() queries. insert() and upsert() don't take filters.
If a Postgres function returns a table response, you can also apply filters.
A filter value is any type that conforms to PostgrestFilterValue. String, the integer and floating-point types, Decimal, Bool, UUID, Date, JSONValue, and arrays of these conform already. Conform your own types to use them as filter values.
nil is not a filter value, so eq("column", value: nil) doesn't compile. Use is("column", value: nil) to match NULL.
The filter methods are eq, neq, gt, gte, lt, lte, like, ilike, is, in, notIn, contains, containedBy, rangeLt, rangeGt, rangeGte, rangeLte, rangeAdjacent, overlaps, and textSearch. 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)
.execute()
let filterByName: String? = nil
let filterPopLow: Int? = 1000
let filterPopHigh: Int? = 10000
var query = 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 City: Decodable {
let name: String
let countryId: Int
enum CodingKeys: String, CodingKey {
case name
case countryId = "country_id"
}
}
let cities: [City] = try await query.execute().value
try await supabase
.from("users")
.select()
.eq("address->postcode", value: 90210)
.execute()
try await supabase
.from("orchestral_sections")
.select(
"""
name,
instruments!inner (
name
)
"""
)
.eq("instruments.name", value: "flute")
.execute()