What are Copy Pipes?
Copy pipes execute a query and copy the results to a datasource either on a schedule or on-demand. Use copy pipes when:- You need periodic snapshots of data
- You want to control when aggregations run
- You’re creating reports or dashboards with point-in-time data
- You want to archive historical data
- You need real-time aggregations
- You want data to update as events arrive
Defining Copy Pipes
UsedefineCopyPipe() to create a copy pipe:
Copy Modes
Control how data is written to the target datasource:Append Mode (Default)
Appends new rows to the datasource on each run:- You’re creating historical snapshots
- Each run produces new data (e.g., daily aggregations)
- You want to keep all historical runs
Replace Mode
Replaces all data in the datasource on each run:- You only need the latest data
- You’re creating reports that show current state
- You want to limit datasource size
Copy Schedules
Define when the copy pipe runs using cron expressions or special values:Cron Expressions
Standard cron format:minute hour day month dayofweek
On-Demand Execution
Manual execution only (no automatic schedule):Complete Examples
Daily Report
Create daily aggregations with historical tracking:Weekly Summary
Create weekly snapshots every Monday:Current State Report
Replace mode for always-current data:Best Practices
Include timestamp in results
Always include a timestamp column (like
snapshot_date) when using append mode to track when each snapshot was taken.Schedule during off-peak hours
Run heavy aggregations during low-traffic periods to minimize impact on your analytics.
Use date functions consistently
Use functions like
yesterday(), today(), toMonday() for consistent time windows.Execution
Copy pipes can be triggered:- Automatically - Based on the
copy_schedulecron expression - Manually - Via the Tinybird UI or API
- On-demand - Using
@on-demandschedule for manual-only execution
Next Steps
Materialized Views
Learn about real-time aggregations
Sink Pipes
Export data to external systems