airflow.providers.google.cloud.transfers.bigquery_to_postgres¶
此模块包含 Google BigQuery 到 PostgreSQL 的 Operator。
类¶
从 BigQuery 表获取数据(或获取选定的列)并插入到 PostgreSQL 表中。 |
模块内容¶
- class airflow.providers.google.cloud.transfers.bigquery_to_postgres.BigQueryToPostgresOperator(*, target_table_name, postgres_conn_id='postgres_default', replace=False, selected_fields=None, replace_index=None, **kwargs)[source]¶
Bases:
airflow.providers.google.cloud.transfers.bigquery_to_sql.BigQueryToSqlBaseOperator
从 BigQuery 表获取数据(或获取选定的列)并插入到 PostgreSQL 表中。
由于 PostgreSQL 的 ON CONFLICT 子句的限制,当使用参数 replace=True 时,需要同时指定 selected_fields 和 replace_index 参数。实际上,这意味着为了使用 replace=True 运行此 Operator,您的目标表必须已经存在一个唯一索引列或多列,否则 INSERT 命令将失败并出现错误。更多信息请参阅 https://postgresql.ac.cn/docs/current/sql-insert.html。
请注意,当前此 Operator 不支持 PostgreSQL INSERT 命令中可用的大多数子句,例如 ON CONSTRAINT、WHERE、DEFAULT 等。如果您在查询中需要这些子句,则 SQLExecuteQueryOperator 将是更合适的选项。
另请参阅
有关如何使用此 Operator 的更多信息,请参阅指南:Operator
- 参数:
target_table_name (str) – 目标 Postgres 表(模板化)
postgres_conn_id (str) – 引用 postgres 连接 ID。
replace (bool) – 是替换而不是插入
selected_fields (list[str] | str | None) – 要返回的字段列表(逗号分隔)。如果未指定,则返回所有字段。如果 replace 为 True,则必须指定。
replace_index (list[str] | str | None) – 作为 ON CONFLICT 子句索引的列名或列名列表。如果 replace 为 True,则必须指定。