SQL to Google Sheets Transfer Operators¶
With Google Sheets, everyone can work together in the same spreadsheet at the same time. Use formulas functions, and formatting options to save time and simplify common spreadsheet tasks.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Select or create a Cloud Platform project using the Cloud Console.
Enable billing for your project, as described in the Google Cloud documentation.
Enable the API, as described in the Cloud Console documentation.
Install API libraries via pip.
pip install 'apache-airflow[google]'Detailed information is available for Installation.
Upload data from SQL to Google Sheets¶
To upload data from and Database using SQL to Google Spreadsheet you can use the
SQLToGoogleSheetsOperator
.
upload_sql_to_sheet = SQLToGoogleSheetsOperator(
task_id="upload_sql_to_sheet",
sql=SQL_SELECT,
sql_conn_id=DB_CONNECTION_ID,
database=DB_NAME,
spreadsheet_id="{{ task_instance.xcom_pull(task_ids='create_spreadsheet', "
"key='spreadsheet_id') }}",
gcp_conn_id=SHEETS_CONNECTION_ID,
)
You can use Jinja templating with
sql
, spreadsheet_id
, spreadsheet_range
, impersonation_chain
.