Skip to content
Advertisement

How to pass parameter in PostgresOperator Airflow using for loop

I am using PostgresOperator and I want to pass table name suffix to my SQL query so when it queries the data, it reads dynamically from the for loop iteration

So as you can see I have passed .format(country) in task_id. I want to do similar stuff by passing country name like in the below SQL statement but seems like Airflow doesn’t like it. Please suggest a correct way As at the end I have passed .format country at the end of my SQL statement

—– Update, I was able to find a solution——– I added an extra coutry key word in the .format(country,country)

Advertisement

Answer

You have an extra parenthesis that is making it not work. Also, I think f-string is more readable than .format. With this, it would work:

By the way, it is a good practice to make unloads from Redshift using an IAM Role instead of credentials, so that they don’t appear in the logs.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement