【问题标题】:How to Call stored procedure function in airflow using PostgresOperator如何使用 PostgresOperator 在气流中调用存储过程函数
【发布时间】:2022-01-06 16:32:13
【问题描述】:

我不确定如何在气流运算符中调用存储过程- 例如。 存储过程是-调用goal.dba.sp_ctrl_calendar()

我的代码-

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)

这种方法正确吗?

【问题讨论】:

    标签: python sql stored-procedures airflow mwaa


    【解决方案1】:

    在 postgresql(或 redshift)中调用 proc ,命令是 call procname 所以你的 sql 命令应该是这样的:

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

    【讨论】:

      【解决方案2】:

      正确答案是-

      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)
      

      【讨论】:

        猜你喜欢
        • 2020-01-03
        • 2022-08-03
        • 1970-01-01
        • 2021-08-22
        • 2011-04-29
        • 1970-01-01
        • 2020-05-10
        • 2015-10-21
        • 2017-04-23
        相关资源
        最近更新 更多