What a weekly SQL report needs
The job sounds small: every Monday at 8, run a query and send the rows to a few people. It has more parts than that.
- A database login that can only read, ideally on a replica.
- The query, written and checked by someone who knows the business.
- A schedule with a time zone, so 8:00 means 8:00 where the readers are.
- A format people can open: an e-mail table, CSV, Excel or PDF.
- A channel: e-mail, a chat tool or a spreadsheet.
- A record of what ran, and a signal when it fails.
The do-it-yourself way: cron, a script and a mailer
The classic version is a shell or Python script that runs the query, writes a CSV and mails it. A crontab line starts it.
0 8 * * 1 /opt/reports/weekly_revenue.sh >> /var/log/weekly_revenue.log 2>&1#!/bin/shpsql "$REPORT_DB_URL" --csv -c " SELECT region, sum(total) AS revenue FROM orders WHERE created_at >= date_trunc('week', now()) - interval '7 days' AND created_at < date_trunc('week', now()) GROUP BY 1 ORDER BY 2 DESC" > /tmp/weekly_revenue.csv echo "Weekly revenue attached." | mail -s "Weekly revenue" -A /tmp/weekly_revenue.csv team@example.comThis works on the first day. The trouble comes later, and it is predictable.
| What breaks | How it shows up |
|---|---|
| Credentials | The password sits in a script or an environment file. It expires or rotates, and the report stops with nobody told. |
| Silent failure | Cron only mails errors if mail is set up on the server. A failed run looks the same as a quiet week. |
| Time zones | Cron runs in the server zone. Daylight saving changes or a server move shift the delivery hour. |
| Retries | If the database is down at 08:00, the report is simply skipped. Nobody retries. |
| Formatting | CSV opens badly in Excel with the wrong separator or encoding. Building a nice table or PDF means more code. |
| Empty weeks | Zero rows still sends a message, and people learn to ignore it. |
| People | The author leaves, the server is retired, and nobody knows the report existed until someone asks where it went. |
None of this is hard to fix one at a time. The cost is that you now own a small piece of infrastructure for every report.
The DataRunner way, step by step
DataRunner takes the scheduler, the formats, the channels, the run history and the failure alert off your hands. You supply the database and the question. These are the steps.
- Connect the database. Create the account (the Solo plan is free, with no card), add the connection and test it. If the database is in a private network, install the bridge agent, which opens the connection from inside out, so no inbound port is needed. Use a read-only login.
- Write the query, or ask the assistant. You can paste SQL, or describe the report in plain words, such as "revenue by region for the last 7 days, biggest first". The assistant reads only the schema (tables, columns, types and column descriptions). No rows of your data are sent to the model.
- Approve the SQL. Every proposal appears on screen and nothing is created until you approve it item by item. Run it once in the workbench to see the result and the row count.
- Schedule it. Set a cron expression, for example 0 8 * * 1 for Monday at 08:00, and choose the time zone of the schedule. The time zone belongs to the schedule, so the same report can go at 08:00 in São Paulo and in Lisbon.
- Pick the channel and the format. E-mail, Slack, WhatsApp (beta), Telegram, Discord, a signed webhook or Google Sheets. For the file, choose inline HTML, CSV, Excel or PDF.
- Skip empty runs. Add the delivery rule that skips the send when the result is empty, or sends only above a row count, so people only get the message when there is something to read.
- Check the run history. Each trigger records start time, duration, rows returned and the database error if there was one. A failed run does not switch the schedule off, and you can route a failure alert to a channel.
E-mail sends through the mail provider you configure for the workspace (SMTP or Resend), from your own domain. There is no fallback to a platform sender, so a workspace without a provider fails the delivery instead of sending from a domain you did not choose.
Choosing the format
| Format | Use it when |
|---|---|
| Inline HTML | A few rows that people read on a phone without opening an attachment |
| CSV | The file feeds another system, or the volume is large |
| Excel (XLSX) | The reader will filter, sum and copy the data |
| The document must look the same for everyone |
For a manager who reads on a phone, a short inline table beats an attachment. For finance, Excel is usually the file they want. Decide by what the reader does next with the numbers.
Write the query so the report stays correct
Most wrong reports come from the date range, not from the tool. Use half-open ranges that end at a fixed boundary, and do not depend on "now" in the middle of a week.
SELECT region, count(*) AS orders, sum(total) AS revenueFROM ordersWHERE created_at >= date_trunc('week', now()) - interval '7 days' AND created_at < date_trunc('week', now())GROUP BY regionORDER BY revenue DESC;- Name the columns the way the reader says them. "revenue" beats "sum".
- Sort the rows. A report with random order is hard to compare week to week.
- Limit the rows when only the top matters.
- Mind the time zone of the database against the time zone of the schedule when you cut the week.
When the script is the better choice
A script is fine if you have one report, one reader, a team that already runs jobs and a place to see failures. It is also the right choice when the output needs custom code, such as a chart rendered by your own library, or a step that changes data.
A tool pays off when the reports multiply, when the reader is not technical, or when the person who wrote the script is not the person who will fix it. DataRunner is also not a BI or ETL replacement: its dashboards are saved SQL drawn as table, number, line, bar or pie, and it does not move data between systems.