importdatetimeimportosimportairflowfromairflow.providers.common.sql.operators.sqlimportSQLExecuteQueryOperatorSQL_DATABASE=os.environ["SQL_DATABASE"]withairflow.DAG("airflow_db_connection_example",start_date=datetime.datetime(2025,1,1),schedule_interval=None,catchup=False)asdag:SQLExecuteQueryOperator(task_id="run_airflow_db_query",dag=dag,conn_id="airflow_db",database=SQL_DATABASE,sql="SELECT * FROM dag LIMIT 10;",)
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-06-30 (世界標準時間)。"],[[["This page details how to connect to and run SQL queries on the Airflow database of your Cloud Composer 1 environment."],["Directly accessing the Airflow database is discouraged; the Airflow REST API or Airflow CLI commands are the recommended alternatives."],["Connecting to the Airflow database involves creating and uploading a DAG that utilizes the `PostgresOperator` to specify and run the SQL query."],["Avoid adding custom tables or modifying the schema of the existing Airflow database to prevent complications."],["Backing up the environment's data should be done with snapshots instead of dumping the database."]]],[]]