Skip to content

Treasury

Query federal debt, operating cash, deposits, withdrawals and public debt transactions, and discover Fiscal Data endpoint fields

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/treasury/index.md to help me query Treasury with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Track US federal debt over time

Example output · captured
Connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
Result
record_date tot_pub_debt_out_amt
2024-01-02 33,990,128,000,000
2024-01-03 33,994,220,000,000

Quick start

Choose where to run Treasury, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'treasury' AS treasury (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-treasury-worker'
);

3. Run a query

query.sql
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'treasury' AS treasury (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-treasury-worker'
);

Overview

US Treasury Fiscal Data as SQL tables, covering federal debt, operating cash, deposits and withdrawals, public debt transactions, monthly statements and average interest rates, with exact decimal amounts. No API key needed.

Catalog

Everything treasury exposes once attached — read straight from the worker's released build.

treasury 1 schema
main 9 functions

Treasury Fiscal Data endpoints as table functions: debt, cash, transactions, statements and interest rates.

Schema examples (12)
Examples (12)

Discover fiscal datasets

SELECT dataset, endpoint, amount_units
FROM treasury.main.datasets()
ORDER BY dataset;

Inspect endpoint fields

SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name;

Read arbitrary fiscal records

SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;

Label every field of one raw record from an uncurated endpoint (the second line of Monthly Treasury Statement Table 9 for January 2024, Individual Income Taxes): fields() supplies each source field's label and type, records() the original JSON value as text

SELECT f.field_name, f.label, f.source_type,
  r.record_json ->> f.field_name AS source_value
FROM treasury.main.records('v1/accounting/mts/mts_table_9', start_date := '2024-01-31', end_date := '2024-01-31', page_size := 1, start_page := 2, max_rows := 1) AS r
CROSS JOIN treasury.main.fields('v1/accounting/mts/mts_table_9') AS f
ORDER BY f.field_name;
8 more examples

Federal debt to the penny

SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
Result
record_date tot_pub_debt_out_amt
2024-01-02 33,990,128,000,000
2024-01-03 33,994,220,000,000

Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded

WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date;

Operating cash balance

SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr;

Compare the Treasury General Account closing cash balance (operating_cash_balance; since April 2022 the closing balance is the open_today_bal of the Closing Balance row, in USD millions) with total public debt outstanding (debt_to_penny) for each business day, as a percentage of debt

WITH tga AS (SELECT record_date, open_today_bal * 1000000 AS tga_close_usd FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-12') WHERE account_type = 'Treasury General Account (TGA) Closing Balance') SELECT d.record_date, d.tot_pub_debt_out_amt, t.tga_close_usd, round(100 * t.tga_close_usd / d.tot_pub_debt_out_amt, 2) AS tga_pct_of_debt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12') AS d
JOIN tga AS t USING (record_date)
ORDER BY d.record_date;

Cash deposits and withdrawals

SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;

Public debt transactions

SELECT transaction_type, security_type, transaction_today_amt
FROM treasury.main.public_debt_transactions(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;

Monthly Treasury receipts and outlays

SELECT classification_desc, current_month_gross_rcpt_amt,
  current_month_gross_outly_amt
FROM treasury.main.monthly_statement(start_date := '2024-01-31', end_date := '2024-01-31')
WHERE data_type_cd='D'
ORDER BY src_line_nbr;

Average interest rates

SELECT security_desc, avg_interest_rate_amt
FROM treasury.main.average_interest_rates(start_date := '2024-01-31', end_date := '2024-01-31')
ORDER BY security_desc;
Table functions
average_interest_rates (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 1 example

Monthly average interest rates on outstanding Treasury securities; values are percentages, not fractions.

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
security_type_desc VARCHAR
Security Type Description.
security_desc VARCHAR
Security Description.
avg_interest_rate_amt DECIMAL(38, 6)
Average Interest Rate Amount. Exact source amount; percent; no rescaling.
src_line_nbr BIGINT
Source Line Number.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Example

Average interest rates

SELECT security_desc, avg_interest_rate_amt
FROM treasury.main.average_interest_rates(start_date := '2024-01-31', end_date := '2024-01-31')
ORDER BY security_desc;
Link
datasets (query := VARCHAR) 1 example

Search the worker's curated typed endpoints, amount scales and interpretation notes. This local catalog is not an exhaustive listing of every Treasury API dataset; use records() for other relative Fiscal Data routes.

Named arguments
query := VARCHAR
Case-insensitive substring matched against each catalog entry; empty returns every entry. · default ""
Returns columns
dataset VARCHAR
Name of a typed worker function.
endpoint VARCHAR
Relative Fiscal Data route for fields or records.
title VARCHAR
Dataset title.
amount_units VARCHAR
Source amount scale; generic API amounts are not rescaled.
description VARCHAR
Scope and interpretation notes.
Example

Discover fiscal datasets

SELECT dataset, endpoint, amount_units
FROM treasury.main.datasets()
ORDER BY dataset;
Link
debt_to_penny (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 2 examples

Daily debt held by the public, intragovernmental holdings and total public debt; exact API amounts.

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
debt_held_public_amt DECIMAL(38, 2)
Debt Held by the Public. Exact source amount; USD; no rescaling.
intragov_hold_amt DECIMAL(38, 2)
Intragovernmental Holdings. Exact source amount; USD; no rescaling.
tot_pub_debt_out_amt DECIMAL(38, 2)
Total Public Debt Outstanding. Exact source amount; USD; no rescaling.
src_line_nbr BIGINT
Source Line Number.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Examples (2)

Federal debt to the penny

SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
Result
record_date tot_pub_debt_out_amt
2024-01-02 33,990,128,000,000
2024-01-03 33,994,220,000,000

Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded

WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date;
Link
deposits_withdrawals (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 1 example

Daily Treasury cash deposits and withdrawals, including month-to-date and fiscal-year-to-date figures. Categories and totals may overlap; filter before aggregation.

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
account_type VARCHAR
Type of Account.
transaction_type VARCHAR
Transaction Type.
transaction_catg VARCHAR
Transaction Category.
transaction_catg_desc VARCHAR
Transaction Category Description.
transaction_today_amt DECIMAL(38, 0)
Transactions Today. Exact source amount; USD millions; no rescaling.
transaction_mtd_amt DECIMAL(38, 0)
Transactions Month to Date. Exact source amount; USD millions; no rescaling.
transaction_fytd_amt DECIMAL(38, 0)
Transactions Fiscal Year to Date. Exact source amount; USD millions; no rescaling.
table_nbr VARCHAR
Table Number.
table_nm VARCHAR
Table Name.
src_line_nbr BIGINT
Source Line Number.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Example

Cash deposits and withdrawals

SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
Link
fields (endpoint VARCHAR) 1 example

Read live field metadata for a relative Fiscal Data endpoint. Fetches a single source row to obtain metadata; it emits only field names, labels, source types and format descriptors.

Arguments
endpoint VARCHAR
Relative Fiscal Data endpoint, e.g. v2/accounting/od/debt_to_penny. Absolute URLs and traversal are forbidden.
Returns columns
field_name VARCHAR
Source API field name.
label VARCHAR
Source field label.
source_type VARCHAR
Treasury's type identifier, such as DATE or CURRENCY.
source_format VARCHAR
Source display-format descriptor; not an inferred scale conversion.
Example

Inspect endpoint fields

SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name;
Link
monthly_statement (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 1 example

Monthly Treasury Statement table 1, including headers and subtotals. record_date identifies the report; classification_desc and record_type_cd identify the represented period. Raw API amounts are not scaled to the website display.

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
parent_id VARCHAR
Parent ID.
classification_id VARCHAR
Classification ID.
classification_desc VARCHAR
Classification Description.
current_month_gross_rcpt_amt DECIMAL(38, 2)
Current Month Gross Receipts Amount. Exact source amount; API currency units; no rescaling.
current_month_gross_outly_amt DECIMAL(38, 2)
Current Month Gross Outlay Amount. Exact source amount; API currency units; no rescaling.
current_month_dfct_sur_amt DECIMAL(38, 2)
Current Month Deficit Surplus Amount. Exact source amount; API currency units; no rescaling.
table_nbr VARCHAR
Table Number.
src_line_nbr BIGINT
Source Line Number.
print_order_nbr VARCHAR
Print Order Sequence Number.
line_code_nbr VARCHAR
Line Code Number.
data_type_cd VARCHAR
Data Type Code.
record_type_cd VARCHAR
Record Type Code.
sequence_level_nbr VARCHAR
Sequence Level Number.
sequence_number_cd VARCHAR
Sequence Number Code.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Example

Monthly Treasury receipts and outlays

SELECT classification_desc, current_month_gross_rcpt_amt,
  current_month_gross_outly_amt
FROM treasury.main.monthly_statement(start_date := '2024-01-31', end_date := '2024-01-31')
WHERE data_type_cd='D'
ORDER BY src_line_nbr;
Link
operating_cash_balance (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 2 examples

Daily Treasury operating cash balances. Since April 2022 some closing fields are null; account_type distinguishes opening and closing balance rows.

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
account_type VARCHAR
Type of Account.
close_today_bal DECIMAL(38, 0)
Closing Balance Today. Exact source amount; USD millions; no rescaling.
open_today_bal DECIMAL(38, 0)
Opening Balance Today. Exact source amount; USD millions; no rescaling.
open_month_bal DECIMAL(38, 0)
Opening Balance This Month. Exact source amount; USD millions; no rescaling.
open_fiscal_year_bal DECIMAL(38, 0)
Opening Balance This Fiscal Year. Exact source amount; USD millions; no rescaling.
table_nbr VARCHAR
Table Number.
table_nm VARCHAR
Table Name.
sub_table_name VARCHAR
Sub Table Name.
src_line_nbr BIGINT
Source Line Number.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Examples (2)

Operating cash balance

SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr;

Compare the Treasury General Account closing cash balance (operating_cash_balance; since April 2022 the closing balance is the open_today_bal of the Closing Balance row, in USD millions) with total public debt outstanding (debt_to_penny) for each business day, as a percentage of debt

WITH tga AS (SELECT record_date, open_today_bal * 1000000 AS tga_close_usd FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-12') WHERE account_type = 'Treasury General Account (TGA) Closing Balance') SELECT d.record_date, d.tot_pub_debt_out_amt, t.tga_close_usd, round(100 * t.tga_close_usd / d.tot_pub_debt_out_amt, 2) AS tga_pct_of_debt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12') AS d
JOIN tga AS t USING (record_date)
ORDER BY d.record_date;
Link
public_debt_transactions (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 1 example

Public debt issues and redemptions by security type in USD millions. transaction_type distinguishes Issues and Redemptions; security_market distinguishes Marketable and Nonmarketable. security_type retains source classifications such as Bills, Notes, Bonds and Government Account Series; inspect distinct values in your date window rather than assuming a fixed enumeration. transaction_today_amt is daily, transaction_mtd_amt is month-to-date, and transaction_fytd_amt is fiscal-year-to-date. These are overlapping measures; do not sum them together or sum cumulative values across dates. For operating cash use operating_cash_balance(); for deposits and withdrawals use deposits_withdrawals().

Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Record Date. Source report/record date, not necessarily the period described by every row.
transaction_type VARCHAR
Transaction Type.
security_market VARCHAR
Security Marketability.
security_type VARCHAR
Security Type.
security_type_desc VARCHAR
Security Type Description.
transaction_today_amt DECIMAL(38, 0)
Transactions Today. Exact source amount; USD millions; no rescaling.
transaction_mtd_amt DECIMAL(38, 0)
Transactions Month to Date. Exact source amount; USD millions; no rescaling.
transaction_fytd_amt DECIMAL(38, 0)
Transactions Fiscal Year to Date. Exact source amount; USD millions; no rescaling.
table_nbr VARCHAR
Table Number.
table_nm VARCHAR
Table Name.
src_line_nbr BIGINT
Source Line Number.
record_fiscal_year BIGINT
Fiscal Year.
record_fiscal_quarter BIGINT
Fiscal Quarter Number.
record_calendar_year BIGINT
Calendar Year.
record_calendar_quarter BIGINT
Calendar Quarter Number.
record_calendar_month BIGINT
Calendar Month Number.
record_calendar_day BIGINT
Calendar Day Number.
source_json VARCHAR
Complete original row preserving source text and any additional fields.
amount_units VARCHAR
Source amount scale for this endpoint; not a conversion factor.
Example

Public debt transactions

SELECT transaction_type, security_type, transaction_today_amt
FROM treasury.main.public_debt_transactions(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
Link
records (endpoint VARCHAR, end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT) 2 examples

Stream exact source records from any relative Fiscal Data v1/v2 route. record_json preserves every field; inspect fields() before extracting values. The default sort assumes record_date and src_line_nbr; choose sort_fields for endpoints with different keys.

Positional arguments
endpoint VARCHAR
Relative public Fiscal Data endpoint; use fields() to inspect its schema.
Named arguments
end_date := VARCHAR
Inclusive record_date upper bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
filters_json := VARCHAR
Array of field/op/value objects; operators eq, lt, lte, gt, gte and in. Values are strings/integers; in takes an array. · default "[]"
max_rows := BIGINT
Explicit output cap; zero streams all matching records. · default 0
page_size := BIGINT
Rows requested per API page; remains fixed throughout pagination. · default 1000
sort_fields := VARCHAR
Comma-separated source sort fields; prefix '-' for descending. Include a unique tie-breaker for stable pagination. · default "record_date,src_line_nbr"
start_date := VARCHAR
Inclusive record_date lower bound, YYYY-MM-DD; empty leaves it unbounded. · default ""
start_page := BIGINT
One-based upstream page to start from, using the selected page_size. · default 1
Returns columns
record_date DATE
Source record date when present; not necessarily the observation period.
record_json VARCHAR
Complete original row with exact source strings and null markers.
Examples (2)

Read arbitrary fiscal records

SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;

Label every field of one raw record from an uncurated endpoint (the second line of Monthly Treasury Statement Table 9 for January 2024, Individual Income Taxes): fields() supplies each source field's label and type, records() the original JSON value as text

SELECT f.field_name, f.label, f.source_type,
  r.record_json ->> f.field_name AS source_value
FROM treasury.main.records('v1/accounting/mts/mts_table_9', start_date := '2024-01-31', end_date := '2024-01-31', page_size := 1, start_page := 2, max_rows := 1) AS r
CROSS JOIN treasury.main.fields('v1/accounting/mts/mts_table_9') AS f
ORDER BY f.field_name;
Link

Try these queries

debt_to_penny_endpoint — Look up the Fiscal Data endpoint behind debt_to_penny in the worker's curated dataset catalog (no network request)

SELECT dataset, endpoint
FROM treasury.main.datasets()
WHERE dataset = 'debt_to_penny';

Uses datasets

Inspect endpoint fields

SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name

Uses fields

Read arbitrary fiscal records

SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date

Uses records

Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded

WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date

Uses debt_to_pennypublic_debt_transactions

Operating cash balance

SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr

Uses operating_cash_balance

Cash deposits and withdrawals

SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr

Uses deposits_withdrawals

6 more examples in the Catalog, each listed under the table or function it uses.

Treasury is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.