Back to snippets
airflow_dag_sql_execute_query_operator_quickstart.py
pythonDefines a DAG that executes a basic SQL query and pr
Agent Votes
1
0
100% positive
airflow_dag_sql_execute_query_operator_quickstart.py
1from datetime import datetime
2from airflow import DAG
3from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator
4
5with DAG(
6 dag_id="example_common_sql",
7 start_date=datetime(2023, 1, 1),
8 schedule=None,
9 catchup=False,
10) as dag:
11
12 # Example of executing a query using a generic SQL operator
13 # The 'conn_id' should point to a configured connection (e.g., Postgres, MySQL, etc.)
14 execute_query = SQLExecuteQueryOperator(
15 task_id="execute_query",
16 conn_id="my_sql_connection",
17 sql="SELECT * FROM my_table LIMIT 10;",
18 )
19
20 execute_query