The Problem
PowerSync pre-computes and caches which rows belong to which parameters to enable efficient streaming. This means parameter-based filtering is limited to equality checks (=, IN, IS NULL) — range operators like >, <, >=, or <= are not supported on parameters.
Additionally, time-based functions like now() aren’t allowed in parameter expressions because the result changes depending on when the query runs, making pre-computation impossible.
These constraints apply to both Sync Streams and legacy Sync Rules.
This guide covers a few practical workarounds.
We are working on a more elegant solution for this problem. When ready, this guide will be updated accordingly.
Workarounds
1: Pre-Defined Time Ranges
Add a boolean column to your table that indicates whether a row falls within a specific time range. Keep this column updated in your source database using a scheduled job. For example, add anupdated_this_week column:
pg_cron):
- Sync Streams
- Sync Rules (Legacy)
2: Buckets Per Date
Instead of pre-defined ranges, create a bucket for each date and let the client specify which dates to sync. Usesubstring to extract the date portion from a timestamp and match it with =:
For a complete working example, see the PowerSync + Supabase: Time-Based Sync demo.
- Sync Streams
- Sync Rules (Legacy)
3: Multiple Granularities
Combine multiple granularities in a single definition. This lets you use larger buckets (days) for older data and smaller buckets (hours, minutes) for recent data.- Sync Streams
- Sync Rules (Legacy)
When using multiple time granularities (e.g., monthly, daily, hourly), rows move between buckets as time passes. Since each granularity creates a different bucket ID, the client must re-download the row from the new bucket even if it already has the data. This re-download overhead can nullify the benefits of granular filtering. For this reason, in some cases it may be better to sync entire months avoiding the re-sync overhead, even if you sync more data initially.
Conclusion
Time-based sync is a common need, but PowerSync doesn’t support range operators or time-based functions on parameters directly. To recap the workarounds:- Pre-defined time ranges — Simplest option. Use when you have a fixed set of time ranges and don’t mind schema changes.
- Buckets Per Date — More flexible. Use when you need arbitrary date ranges but can live with a single granularity.
- Multiple Granularities — Most flexible. Use when you need precision for recent data without syncing hundreds of buckets. Be mindful of the re-sync overhead.