airflow.providers.google.cloud.transfers.bigquery_to_postgres
¶
這個模組包含 Google BigQuery 到 PostgreSQL 的運算子。
模組內容¶
類別¶
從 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 執行此運算子,您的目標表格必須已經有一個唯一的索引欄位/欄位,否則 INSERT 命令將會失敗並出現錯誤。詳情請見 https://postgresql.dev.org.tw/docs/current/sql-insert.html。
請注意,目前此運算子不支援 PostgreSQL 的 INSERT 命令可以使用的大多數子句,例如 ON CONSTRAINT、WHERE、DEFAULT 等。如果您的查詢需要這些子句,SQLExecuteQueryOperator 將會是更合適的選項。
另請參閱
有關如何使用此運算子的更多資訊,請參閱指南: 運算子
- 參數
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,則必須指定