kameshkotwani opened a new issue, #27077:
URL: https://github.com/apache/airflow/issues/27077

   ### Apache Airflow version
   
   main (development)
   
   ### What happened
   
    I am trying to pass a sql parameter as a Jinja Template, but not able to. I 
am a bit new to Airflow, here is the code, I am not sure if the Jinja 
templating works in PostgresOperator or not. If there is any other way we can 
pass please let me know, again I am not trying to pass the jinja template 
inside the SQL query or file, I am passing the name of the SQL file using the 
Jinja template which it is not able to render.
   
   ### What you think should happen instead
   
   The Jinja Template should be rendered at `sql` parameter in PostgresOperator.
   
   ### How to reproduce
   
   ```
   write_to_postgres = PostgresOperator(
           task_id ="write_to_postgres",
           postgres_conn_id="mypostgres",
           #TODO investigate, why this is not working
           sql ="queries{{ execution_date.hour }}{{ execution_date.day }}.sql"
       )
   ``` 
   Output of rendered in PostgresOperator
   
![brave_4cWYODo9ih](https://user-images.githubusercontent.com/36355951/196022184-36dfa60c-81d8-4662-a070-9129ad21b7d6.jpg)
   
   
   However, the BashOperator is able to render it properly
   
   ```bash
     delete_queries_file = BashOperator(
           task_id ="delete_queries_file",
           bash_command="cd /opt/airflow/dags && rm queries{{ 
execution_date.hour }}{{ execution_date.day }}.sql"
       )
   ```
   
   Output of the BashOperator with proper rendered of Jinja Template
   
![brave_lfK8o7p6Av](https://user-images.githubusercontent.com/36355951/196022293-9a5f7c0f-f19e-45b7-91c6-1079e8aaea96.jpg)
   
   
   ### Operating System
   
   Windows 10 
   
   ### Versions of Apache Airflow Providers
   
   apache-airflow-providers-common-sql==1.2.0
   apache-airflow-providers-ftp==3.1.0     
   apache-airflow-providers-http==4.0.0    
   apache-airflow-providers-imap==3.0.0    
   apache-airflow-providers-postgres==5.2.2
   apache-airflow-providers-sqlite==3.2.1 
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   _No response_
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to