Skip to content

Conversation

@khawarizmus
Copy link

Documents how to implement time-based filtering with current sync rule limitations.

Covers three workarounds:

  • Boolean columns
  • Buckets per date
  • Multiple granularities

Highlighted trade-offs for each


# The Problem

Sync rules only support a limited set of operators when filtering on parameters. You can use `=`, `IN`, and `IS NULL`, but not range operators like `>`, `<`, `>=`, or `<=`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a hyperlink to operators to https://docs.powersync.com/usage/sync-rules/operators-and-functions for more details


This gives users full control over which dates to sync, with no schema changes or scheduled jobs required.

The trade-off is granularity. In this example we're using daily buckets. If you need finer precision (hourly), syncing a large range means many buckets. If you use larger buckets (monthly), you lose the ability to filter accurately.
Copy link
Collaborator

@benitav benitav Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncing a large range means many buckets.

It would be good to add why many buckets are a problem. i.e. I assume the main consideration is the 1,000 bucket limit

**Cons:** Requires schema changes and scheduled jobs (e.g., pg_cron). Limited to pre-defined time ranges.
</Warning>

If you need more flexibility like letting users pick arbitrary date ranges [see Workaround 2](#2:-buckets-per-date).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The links here feel a bit weird because they just link to the next line. Feels like we could just say "see the next workaround: Buckets Per Date" or similar

khawarizmus and others added 3 commits January 12, 2026 08:10
Co-authored-by: benitav <benitav@users.noreply.github.com>
Co-authored-by: benitav <benitav@users.noreply.github.com>
@khawarizmus khawarizmus marked this pull request as ready for review January 12, 2026 23:55
Copy link
Contributor

@michaelbarnes michaelbarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor wording changes.


# Workarounds

## 1: Boolean Columns
Copy link
Contributor

@michaelbarnes michaelbarnes Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rather call this "Pre-defined time ranges".

This approach works well when you have a small, fixed set of time ranges. However, it requires schema changes and a scheduled job to keep the columns updated.

<Warning>
**Cons:** Requires schema changes and scheduled jobs (e.g., pg_cron). Limited to pre-defined time ranges.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the word "Cons", I think the Warning component highlights the "con" aspect of this approach.

The trade-off is granularity. In this example we're using daily buckets. If you need finer precision (hourly), syncing a large range means many buckets, which can degrade sync performance and approach [PowerSync's limit of 1,000 buckets per user](https://docs.powersync.com/resources/performance-and-limits#performance-and-limits). If you use larger buckets (monthly), you lose the ability to filter accurately.

<Warning>
**Cons:** Must commit to a single granularity. Daily = too many buckets for long ranges. Monthly = lose precision for recent data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "Cons:". Similar to the previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants