Bulk Load CSV Data into PostgreSQL Using COPY for Fast ETL Ingestion
Bulk load a CSV file into PostgreSQL with the native COPY protocol for fast, reliable ETL ingestion.
Ingest US Treasury interest rates monthly, diff against historical trends in DuckDB, export partitioned Parquet to internal storage and alert on rate spikes.
The US Department of the Treasury publishes monthly average interest rates across all outstanding marketable securities (Treasury Bills, Notes, Bonds, and TIPS) and non-marketable debt obligations. Corporate treasury desks, quantitative risk analysts, and macro data engineers track these benchmark yields to model corporate borrowing costs, calculate discount curves, and assess macroeconomic interest rate exposure.
This flow automates the ingestion of the official Fiscal Data REST API, diffs the newest monthly yield curve against accepted historical values inside an embedded DuckDB engine, writes persistent columnar Parquet files into Kestra internal storage, maintains state across executions using Kestra KV store, and triggers targeted Slack alerts when benchmark rates shift beyond an operational basis point threshold.
Schedule trigger is configured to execute on the 5th of each month (09:00 UTC), allowing sufficient buffer for the US Treasury to publish and finalize prior month figures.fetch_treasury_rates (io.kestra.plugin.core.http.Download) queries the US Treasury Fiscal Data API (api.fiscaldata.treasury.gov) for all average interest rate records matching the configured starting date, landing the JSON payload into Kestra internal storage.previous_rates (io.kestra.plugin.core.kv.Get, with errorOnMissing: false) retrieves the storage URI of the Parquet dataset produced during the previous run.bootstrap_history (io.kestra.plugin.core.flow.If) executes only on the initial run when no prior state exists in KV store, generating an empty baseline Parquet file with identical column schemas so downstream diff queries share a single deterministic execution path.diff_and_load (io.kestra.plugin.jdbc.duckdb.Queries, with fetchType: FETCH_ONE) ingests the JSON payload via read_json and unnest, filters out null entries, isolates the latest record for each security description and category, and executes a full join against the baseline Parquet dataset. It calculates basis point deltas (ROUND((current_rate - previous_rate) * 100, 2)), categorizes change types (NEW, CHANGED, UNCHANGED), and outputs three distinct artifacts:latest_rates.parquet: The current snapshot of all active Treasury securities and their latest monthly yields.rates_revision_log.parquet: A multi-period historical time-series Parquet dataset suitable for analytical warehouse loading.rate_changes_summary.csv: A tabular summary of monthly movements sorted by absolute basis point variance.save_rates_kv (io.kestra.plugin.core.kv.Set) stores the internal storage URI of latest_rates.parquet under the key treasury_accepted_rates_uri.alert_on_material_rate_shift (io.kestra.plugin.core.flow.If) evaluates the summary metric material_shifts_count. If one or more securities shifted by more than material_shift_bps, it posts an alert payload to Slack via io.kestra.plugin.slack.notifications.SlackIncomingWebhook. With allowFailure: true, missing webhook credentials issue a graceful warning rather than aborting the pipeline. Otherwise, a standard Log task records peaceful metrics.summary_log records execution telemetry, and the root outputs expose both the Parquet datasets and the summary JSON to downstream flows.Download and inputFiles handle REST API ingestion and file transport directly into DuckDB without custom Python wrappers or container images.outputFiles and KV Store eliminate the overhead of external state databases, preserving dataset URIs across monthly runs.If) and error fault-tolerance (allowFailure) provide declarative alerting logic directly within workflow configuration.io.kestra.plugin.jdbc.duckdb.Queries) and notifications plugin (io.kestra.plugin.slack.notifications.SlackIncomingWebhook).api.fiscaldata.treasury.gov. The Fiscal Data API is open to the public and requires no API key.SLACK_WEBHOOK_URL: Optional Slack incoming webhook URI for receiving material rate shift alerts.treasury_accepted_rates_uri in KV store.latest_rates.parquet and the summary metrics.UNCHANGED, and alerting will be bypassed.SLACK_WEBHOOK_URL secret and enable the monthly Schedule trigger to receive automatic notifications whenever the Treasury Department publishes monthly rate updates.io.kestra.plugin.aws.s3.Upload, io.kestra.plugin.gcp.gcs.Upload) to mirror generated Parquet files directly into your enterprise data lake.