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

   ### Description
   
   Allow to pass a (list of) SqlAlchemy statement in addition to `str` to the 
`sql` parameter of the `SQLExecuteQueryOperator`.
   
   ### Use case/motivation
   
   I need to execute a query either from Airflow or manually.
   So I generate a SqlStatement (`sa.select(...).where(...)`), using 
`bindparam`.
   I can then do: `session.execute(stmt, 
params=dict(data_interval_start=mydate))` for "manual" execution, and I expect 
to be able to do: `SQLExecuteQueryOperator(sql=stmt, 
params=dict(data_interval_start="{{ data_interval_start }}"))` for Airflow.
   
   However, this construct fails, because Airflow operator expect a string. But 
passing `sql=str(stmt)` replaces all bind parameters following a schema like 
`:data_interval_start`, and this does not work for my Postgresql backend 
(`psycopg2.errors.SyntaxError: syntax error at or near ":"`)
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [X] 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