You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/17 08:51:53 UTC
[GitHub] [airflow] kameshkotwani commented on issue #27077: Not able to use Jinja template in PostgresOperator sql parameter as filename
kameshkotwani commented on issue #27077:
URL: https://github.com/apache/airflow/issues/27077#issuecomment-1280510250
Thank you for considering it, meanwhile I was able to do the required task using vanilla python and PythonOperator, I have attached the code, might help someone with same requirement as mine.
```python
def _write_to_postgres(execution_date):
hour = execution_date.hour
day = execution_date.day
filename = f"queries{hour}{day}.sql"
import psycopg2
try:
conn = psycopg2.connect(database="airflow",user='airflow', password='airflow', host='postgres', port= '5432')
except:
raise AirflowFailException
else:
cursor = conn.cursor()
with open(f"/opt/airflow/dags/{filename}","r") as f:
for statement in f.readlines():
print(statement)
cursor.execute(statement)
conn.commit()
cursor.close()
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org