> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/data-engineering/apache-airflow/useful-sql-queries-for-apache-airflow.md).

# Useful SQL queries for Apache Airflow

## Get tasks run

```sql
SELECT * 
FROM task_instance
WHERE 
    dag_id LIKE 'abc%' 
    AND task_id != 'start'
    AND execution_date >= '2020-04-20';
```

## Delete tasks run to trigger backfill

```sql
BEGIN;

    DELETE 
    FROM task_instance
    WHERE 
        dag_id LIKE 'abc%' 
        AND task_id != 'start'
        AND execution_date >= '2020-04-20';
    
    SELECT 1;
COMMIT;
```
