Copy Statements
Copy Statements
Copy statements export query results to files.
Syntax
copy_statement: "copy" "into" COPY_TYPE string_lit "from" select_statement
Where COPY_TYPE is currently: csv
Copy to CSV
Export a select statement to a CSV file:
copy into csv 'output/customers.csv' from
select
customer.id,
customer.name,
customer.email
;
Use Cases
- Data exports
- Report generation
- Data sharing
- Backup snapshots
- ETL outputs
Example
import customer as customer;
import order as order;
copy into csv 'reports/customer_summary.csv' from
select
customer.id,
customer.name,
count(order.id) -> total_orders,
sum(order.amount) -> total_spent
order by
total_spent desc
limit 100
;
Tips
The file path is relative to the execution directory. Ensure the output directory exists before running the copy.
