Filter Builder#

This is a kind of request builder. It contains all the methods used to filter data during queries.

Note

In the source code, there are separate AsyncFilterRequestBuilders and SyncFilterRequestBuilders. These classes are otherwise exactly the same, and provide the same interface.

Warning

These classes are not meant to be constructed by the user.

Tip

The full list of supported filter operators are on the PostgREST documentation

Tip

All the filter methods return a modified instance of the filter builder, allowing fluent chaining of filters.

class postgrest.AsyncFilterRequestBuilder#
__init__(session: AsyncClient, path: str, http_method: str, headers: Headers, params: QueryParams, json: dict) None#
adj(column: str, range: Tuple[int, int]) Self#
cd(column: str, values: Iterable[Any]) Self#
contained_by(column: str, value: Iterable[Any] | str | Dict[Any, Any]) Self#
contains(column: str, value: Iterable[Any] | str | Dict[Any, Any]) Self#
cs(column: str, values: Iterable[Any]) Self#
eq(column: str, value: Any) Self#

An ‘equal to’ filter.

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

async execute() APIResponse[_ReturnT]#

Execute the query.

Tip

This is the last method called, after the query is built.

Returns:

APIResponse

Raises:

APIError

filter(column: str, operator: str, criteria: str) Self#

Apply filters on a query.

Parameters:
  • column – The name of the column to apply a filter on

  • operator – The operator to use while filtering

  • criteria – The value to filter by

fts(column: str, query: Any) Self#
gt(column: str, value: Any) Self#

A ‘greater than’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

gte(column: str, value: Any) Self#

A ‘greater than or equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

ilike(column: str, pattern: str) Self#

An ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

ilike_all_of(column: str, pattern: str) Self#

A ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

ilike_any_of(column: str, pattern: str) Self#

A ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

in_(column: str, values: Iterable[Any]) Self#
is_(column: str, value: Any) Self#

An ‘is’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

like(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

like_all_of(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

like_any_of(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

lt(column: str, value: Any) Self#

A ‘less than’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

lte(column: str, value: Any) Self#

A ‘less than or equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

match(query: Dict[str, Any]) Self#
neq(column: str, value: Any) Self#

A ‘not equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

property not_: Self#

Whether the filter applied next should be negated.

nxl(column: str, range: Tuple[int, int]) Self#
nxr(column: str, range: Tuple[int, int]) Self#
or_(filters: str, reference_table: str | None = None) Self#

An ‘or’ filter

Parameters:
  • filters – The filters to use, following PostgREST syntax

  • reference_table – Set this to filter on referenced tables instead of the parent table

ov(column: str, values: Iterable[Any]) Self#
overlaps(column: str, values: Iterable[Any]) Self#
phfts(column: str, query: Any) Self#
plfts(column: str, query: Any) Self#
range_adjacent(column: str, range: Tuple[int, int]) Self#
range_gt(column: str, range: Tuple[int, int]) Self#
range_gte(column: str, range: Tuple[int, int]) Self#
range_lt(column: str, range: Tuple[int, int]) Self#
range_lte(column: str, range: Tuple[int, int]) Self#
sl(column: str, range: Tuple[int, int]) Self#
sr(column: str, range: Tuple[int, int]) Self#
wfts(column: str, query: Any) Self#
class postgrest.SyncFilterRequestBuilder#
__init__(session: SyncClient, path: str, http_method: str, headers: Headers, params: QueryParams, json: dict) None#
adj(column: str, range: Tuple[int, int]) Self#
cd(column: str, values: Iterable[Any]) Self#
contained_by(column: str, value: Iterable[Any] | str | Dict[Any, Any]) Self#
contains(column: str, value: Iterable[Any] | str | Dict[Any, Any]) Self#
cs(column: str, values: Iterable[Any]) Self#
eq(column: str, value: Any) Self#

An ‘equal to’ filter.

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

execute() APIResponse[_ReturnT]#

Execute the query.

Tip

This is the last method called, after the query is built.

Returns:

APIResponse

Raises:

APIError

filter(column: str, operator: str, criteria: str) Self#

Apply filters on a query.

Parameters:
  • column – The name of the column to apply a filter on

  • operator – The operator to use while filtering

  • criteria – The value to filter by

fts(column: str, query: Any) Self#
gt(column: str, value: Any) Self#

A ‘greater than’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

gte(column: str, value: Any) Self#

A ‘greater than or equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

ilike(column: str, pattern: str) Self#

An ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

ilike_all_of(column: str, pattern: str) Self#

A ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

ilike_any_of(column: str, pattern: str) Self#

A ‘ILIKE’ filter, to use for pattern matching (case insensitive).

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

in_(column: str, values: Iterable[Any]) Self#
is_(column: str, value: Any) Self#

An ‘is’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

like(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

like_all_of(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

like_any_of(column: str, pattern: str) Self#

A ‘LIKE’ filter, to use for pattern matching.

Parameters:
  • column – The name of the column to apply a filter on

  • pattern – The pattern to filter by

lt(column: str, value: Any) Self#

A ‘less than’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

lte(column: str, value: Any) Self#

A ‘less than or equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

match(query: Dict[str, Any]) Self#
neq(column: str, value: Any) Self#

A ‘not equal to’ filter

Parameters:
  • column – The name of the column to apply a filter on

  • value – The value to filter by

property not_: Self#

Whether the filter applied next should be negated.

nxl(column: str, range: Tuple[int, int]) Self#
nxr(column: str, range: Tuple[int, int]) Self#
or_(filters: str, reference_table: str | None = None) Self#

An ‘or’ filter

Parameters:
  • filters – The filters to use, following PostgREST syntax

  • reference_table – Set this to filter on referenced tables instead of the parent table

ov(column: str, values: Iterable[Any]) Self#
overlaps(column: str, values: Iterable[Any]) Self#
phfts(column: str, query: Any) Self#
plfts(column: str, query: Any) Self#
range_adjacent(column: str, range: Tuple[int, int]) Self#
range_gt(column: str, range: Tuple[int, int]) Self#
range_gte(column: str, range: Tuple[int, int]) Self#
range_lt(column: str, range: Tuple[int, int]) Self#
range_lte(column: str, range: Tuple[int, int]) Self#
sl(column: str, range: Tuple[int, int]) Self#
sr(column: str, range: Tuple[int, int]) Self#
wfts(column: str, query: Any) Self#