Skip to content

Simple-style Queries#

This style of querying reads almost like SQL, making most queries easier to write using this style. Multiple conditions can also be joined together using AND/OR clauses in this style, which is not possible in the filter style queries.

Tip

If you have difficulty choosing, just pick this style of queries 😉. It can do everything the filter-style queries can do, and more!

Tip

Refer the PostgREST docs for more info about operators.

Simple example#

from pgrest import Column

res = await client.from_("countries").select("*").where(Column("name") == "India")

Note

The comparison operators (==, !=, >, <, <=, >=) have been implemented directly as Python operators, although they also have equivalent methods on the Column class. That is, Column("name") == "India" and Column("name").eq("India") are both valid.

Join conditions with an OR/AND clause#

res = await client
    .from_("countries")
    .select("*")
    .where(Column("capital") == "Rome" | Column("capital") == "Berlin")
    .execute()
res = await client
    .from_("countries")
    .select("*")
    .where(Column("continent") == "Asia" & Column("population") >= 5000000)
    .execute()
res = await client
    .from_("countries")
    .select("*")
    .where(Column("continent") == "Asia" & Column("population") >= 5000000 | Column("name").ilike("%stan"))
    .execute()

Tip

In case both AND (&) and OR (|) appear in the query, the order of precedence is to first evalute AND, then OR.

Back to top