hammerhead commented on issue #24014: URL: https://github.com/apache/airflow/issues/24014#issuecomment-1143372021
> In this particular example the fix is to use `parameters` not `params` for the PostgresOperator https://airflow.apache.org/docs/apache-airflow-providers-postgres/stable/_api/airflow/providers/postgres/operators/postgres/index.html#airflow.providers.postgres.operators.postgres.PostgresOperator Yes, indeed. The original DAG I ran into the problem with was using different types of queries, such as `DELETE FROM {table_fqn} WHERE {column} = {value};`. In that example, I can't use `parameters` for `{table_fqn}` as `%(table_fqn)s` will wrap the value in single quotes, resulting in an SQL syntax error. Using `params` gives me the plain value instead. See also this [Stack Overflow post](https://stackoverflow.com/questions/70228542/how-to-force-airflow-not-to-put-single-quotes-around-rendered-name-in-postgresop) from another user. Right now, I'm using a Python task as a workaround and then pass it directly to the `sql` paramer of the `PostgresOperator`: ```python @task def generate_sql(policy): return Path('include/data_retention_delete.sql') \ .read_text(encoding="utf-8").format(table_fqn=policy[0], column=policy[1], value=policy[2], ) @dag( start_date=pendulum.datetime(2021, 11, 19, tz="UTC"), schedule_interval="@daily", catchup=False, ) def data_retention_delete(): sql_statements = generate_sql.expand(policy=get_policies()) PostgresOperator.partial( task_id="delete_partition", postgres_conn_id="cratedb_connection", ).expand(sql=sql_statements) ``` -- 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]
