Given a MySqlOperator
and an sql query how do i pass a parameter
and use it?
Here is my code which doesn't work. I am trying to pass the table name as a parameter.
UPDATE_SQL = "UPDATE {table} SET version=version+1 WHERE id='x'"
update_row = MySqlOperator(
dag=dag,
task_id='update_row',
mysql_conn_id=CONNECTION_ID,
parameters={'table': 'hello_world'},
database=MY_DATABASE,
sql=UPDATE_SQL,
)
I could not find any examples on how to use the parameters in the Operator.
You can do it as:
UPDATE_SQL = "UPDATE {{ params.table }} SET version=version+1 WHERE id='x'"
update_row = MySqlOperator(
dag=dag,
task_id='update_row',
mysql_conn_id=CONNECTION_ID,
params={"table": "hello_world"},
database=MY_DATABASE,
sql=UPDATE_SQL,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With