Skip to main content
Parameter Queries allow parameters to be defined on a bucket to group data. Each bucket can have zero or more Parameter Queries. Parameter Queries can return multiple rows/documents. The values selected in each row/document become parameters for the bucket. The following values can be selected in Parameter Queries:
  • Authentication Parameters, which come from the JWT token.
  • Client Parameters, which are passed directly from clients (specified at connection)
  • Values From a Table/Collection (in your source database)
Parameter Queries are not run directly on your source database. Instead, the Parameter Queries in your Sync Rules are used to pre-process rows/documents as they are replicated from your source database. During replication, parameter values are indexed for efficient use in the sync process.

Using Authentication Parameters

The following functions allow you to select Authentication Parameters in your Parameter Queries: Since request.jwt() is a string containing JSON, use the ->> operator to select values from it:
As an example, Supabase Auth includes various claims in their JWTs:
This is a simple example of Sync Rules with a single bucket definition with a Parameter Query that selects the user ID from the JWT:
A legacy syntax for Parameter Queries used token_parameters.user_id to return the JWT subject. Example:
That legacy syntax also allowed custom claims from the JWT, but only if they were nested under a parameters claim in the JWT.If you are still using this legacy syntax, you can migrate to the current syntax as follows:
  1. token_parameters.user_id references can simply be updated to request.user_id()
  2. For custom parameters, if you keep your custom JWT in the format required by the legacy syntax, you can update token_parameters.my_custom_field references to request.jwt() ->> 'parameters.my_custom_field'
  3. Alternatively, you can get custom parameters directly from the JWT payload/claims, e.g. request.jwt() ->> 'my_custom_field'
Example:

Using Client Parameters

Example usage:
For full details, see the dedicated page on Client Parameters.

Using Values From a Table/Collection

A Parameter Query can select a parameter from a table/collection in your source database, for example:

Supported SQL

The supported SQL in Parameter Queries is based on a small subset of the SQL standard syntax. Not all SQL constructs are supported. See Supported SQL for full details.

Usage Examples

Filter on Additional Columns/Fields

Group According to Different Columns/Fields

Using Different Tables/Collections for Parameters

Multiple Columns/Fields

Parameter Queries may select multiple columns/fields parameters.

Using a Join Table/Collection

In this example, the Parameter Query can return multiple rows/documents, resulting in multiple sets of bucket parameters for a single user.
Keep in mind that the total number of buckets per user should remain limited (<= 1,000 by default), so buckets should not be too granular.
For more advanced details on many-to-many relationships and join tables, see this guide.

Expanding JSON Array Into Multiple Parameters

Using the json_each() function and -> operator, we can expand a parameter that is a JSON array into multiple rows, thereby filtering by multiple parameter values:

Multiple Parameter Queries

Multiple Parameter Queries can be used in the same bucket definition, however, the output columns must be exactly the same for each of these Parameter Queries:
Keep in mind that the total number of buckets per user should remain limited (<= 1,000 by default), so buckets should not be too granular.

No Output Columns/Fields

A Parameter Query with no output columns may be specified to only sync the bucket to a subset of users.

No Parameter Query

Any bucket with no Parameter Query in the bucket definition is automatically a Global Bucket. These buckets will be synced to all clients/users. See Global Buckets