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://postgres.tw/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,則必須指定。