Skip to content

Commit 719904e

Browse files
authored
Update README.md
1 parent 57906e4 commit 719904e

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ The DuckDB Cron extension adds support for scheduled query execution within Duck
55

66
> Experimental: USE AT YOUR OWN RISK!
77
8-
98
### Cron Runner
109
```sql
11-
-- Run a query every ten seconds
12-
SELECT cron('SELECT version()', '*/10 * * * * *') AS job_id;
10+
-- Every 15 seconds during hours 1-4
11+
SELECT cron('SELECT now()', '*/15 * 1-4 * * *');
12+
13+
-- Every 2 hours (at minute 0, second 0) during hours 1-4
14+
SELECT cron('SELECT version()', '0 0 */2 1-4 * *');
1315

14-
-- Run a query every hour at minute 0
15-
SELECT cron('SELECT now()', '0 * * * * *') AS job_id;
16+
-- Every Monday through Friday at 7:00:00 AM
17+
SELECT cron('SELECT cleanup()', '0 0 7 ? * MON-FRI');
1618
```
1719

1820
The function returns a job ID that can be used to manage the scheduled task.
@@ -26,6 +28,38 @@ The function returns a job ID that can be used to manage the scheduled task.
2628
└──────────┘
2729
```
2830

31+
#### Supported Expressions
32+
The extension uses six-field cron expressions:
33+
```
34+
┌───────────── second (0 - 59)
35+
│ ┌───────────── minute (0 - 59)
36+
│ │ ┌───────────── hour (0 - 23)
37+
│ │ │ ┌───────────── day of month (1 - 31)
38+
│ │ │ │ ┌───────────── month (1 - 12)
39+
│ │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
40+
│ │ │ │ │ │
41+
* * * * * *
42+
```
43+
44+
##### Special characters:
45+
46+
- `*`: any value
47+
- `?`: no specific value (used in day-of-month/day-of-week)
48+
- `,`: value list separator
49+
- `-`: range of values
50+
- `/`: step values
51+
- `MON-SUN`: named weekdays (case sensitive)
52+
53+
##### Common Patterns:
54+
```
55+
0 0 * * * *: Top of every hour
56+
0 */15 * * * *: Every 15 minutes
57+
0 0 0 * * *: Once per day at midnight
58+
0 0 12 ? * MON-FRI: Weekdays at noon
59+
0 0 0 1 * ?: First day of every month
60+
```
61+
62+
2963
### Listing Jobs
3064
Use the cron_jobs() table function to view all scheduled jobs and their status:
3165
```sql
@@ -41,7 +75,7 @@ SELECT * FROM cron_jobs();
4175

4276
Returns:
4377

44-
- `job_id``: Unique identifier for the job
78+
- `job_id`: Unique identifier for the job
4579
- `query`: The SQL query to execute
4680
- `schedule`: The cron expression
4781
- `next_run`: Next scheduled execution time

0 commit comments

Comments
 (0)