Search code examples
pythonsqlstored-proceduresairflowmwaa

How to Call stored procedure function in airflow using PostgresOperator


I am not sure about how to call stored procedure in airflow operator- eg. Stored Procedure is- Call goal.dba.sp_ctrl_calendar()

My code-

from airflow.operators.postgres_operator import PostgresOperator
sp_ctrl_calendar = PostgresOperator(
        task_id = 'sp_ctrl_calendar',
        sql = 'goal.dba.sp_ctrl_calendar(); end;',
        postgres_conn_id = 'redshift',
        autocommit = True)

Is this approach correct?


Solution

  • The correct answer is-

    sql_command_1 = 'call goal.dba.sp_ctrl_calendar()'
    sp_ctrl_calendar = PostgresOperator(
        task_id = 'sp_ctrl_calendar',
        sql = sql_command_1,
        postgres_conn_id = 'redshift',
        autocommit = True)