Substrate queries
Demo query results
These are the six substrate queries from queries/demo.sql, run against the live srdb.duckdb. Results captured at a fixed point in time.
Substrate queries
These are the six substrate queries from queries/demo.sql, run against the live srdb.duckdb. Results captured at a fixed point in time.
Demonstrates: join of position → instrument → entity, valid-time filter (valid_to IS NULL = current knowledge), snapshot filter (as_of_date), and grouped aggregation across the multi-asset position table.
SELECT
i.asset_class,
e.legal_name AS holding_entity,
SUM(p.market_value_usd) AS total_market_value_usd
FROM position p
JOIN instrument i ON p.instrument_id = i.instrument_id
JOIN entity e ON p.holding_entity_id = e.entity_id
WHERE p.as_of_date = '2025-12-31'
AND p.valid_to IS NULL
GROUP BY i.asset_class, e.legal_name
ORDER BY i.asset_class, e.legal_name| asset_class | holding_entity | total_market_value_usd |
|---|---|---|
| WELL | SRAM Energy Haynesville SPV LLC | $1,156,187.48 |
| WELL | SRAM Energy Marcellus SPV LLC | $1,365,676.60 |
| CRYPTO_DERIV | NYDIG LLC | $10,954,327.92 |
Demonstrates: the vw_position_lookthrough view, which traverses the entity_relationship graph to attribute fund-of-fund positions back to the ultimate investor (LongTail Re / LTRe_BERMUDA). This is the "Hedge Fund Re loop" — LTRe holds SRAM fund LP interests, so its risk exposure is indirect across all SRAM-held instruments.
SELECT
lt.holding_entity_name,
lt.asset_class,
lt.instrument_subtype,
COUNT(*) AS position_count,
SUM(lt.attributed_value_usd) AS total_attributed_value_usd
FROM vw_position_lookthrough lt
WHERE lt.holding_entity_name LIKE '%LongTail%'
GROUP BY lt.holding_entity_name, lt.asset_class, lt.instrument_subtype
ORDER BY lt.asset_class, lt.instrument_subtype| holding_entity_name | asset_class | instrument_subtype | position_count | total_attributed_value_usd |
|---|---|---|---|---|
| LongTail Re Ltd | CRYPTO_DERIV | CME_FUT | 2 | $376,907.93 |
| LongTail Re Ltd | CRYPTO_DERIV | DERIBIT_OPT | 2 | $88,651.01 |
| LongTail Re Ltd | SFR_PORTFOLIO | MSA_PORTFOLIO | 3 | $116,868,571.67 |
| LongTail Re Ltd | TREATY | CASUALTY_QS | 4 | -$8,815,090.41 |
| LongTail Re Ltd | TREATY | CAT_XOL | 3 | -$1,116,164.38 |
| LongTail Re Ltd | WELL | HORIZONTAL_GAS | 6 | $643,075.34 |
Demonstrates: txn-time (transaction-time) as-of query. The position table is fully bitemporal: valid_time tracks what we held, txn_time tracks when our database captured that knowledge. Filtering txn_from/txn_to to a past knowledge date reconstructs the state of the database at that point in time.
SELECT
p.position_id,
p.as_of_date,
p.quantity,
p.quantity_unit,
p.market_value_usd,
p.txn_from,
p.txn_to
FROM position p
WHERE p.as_of_date = '2024-06-15'
AND p.instrument_id = '00000000-0000-0000-0201-000000000001'
AND p.txn_from <= TIMESTAMPTZ '2024-06-30 00:00:00+00'
AND (p.txn_to IS NULL OR p.txn_to > TIMESTAMPTZ '2024-06-30 00:00:00+00')| position_id | as_of_date | quantity | quantity_unit | market_value_usd | txn_from | txn_to |
|---|---|---|---|---|---|---|
| 00000000-0000-0000-0401-000000000001 | 2024-06-15 | 1,000 | CONTRACTS | $5,100,000.00 | 2024-06-16T05:00:00-04:00 | 2024-06-30T05:00:00-04:00 |
Demonstrates: same valid-time date as Query 3a, but without the past txn-time filter, returning the current database state after the correction was applied.
SELECT
p.position_id,
p.as_of_date,
p.quantity,
p.quantity_unit,
p.market_value_usd,
p.txn_from,
p.txn_to
FROM position p
WHERE p.as_of_date = '2024-06-15'
AND p.instrument_id = '00000000-0000-0000-0201-000000000001'
AND p.txn_to IS NULL| position_id | as_of_date | quantity | quantity_unit | market_value_usd | txn_from | txn_to |
|---|---|---|---|---|---|---|
| 00000000-0000-0000-0401-000000000002 | 2024-06-15 | 1,010 | CONTRACTS | $5,151,000.00 | 2024-06-30T05:00:00-04:00 | NULL |
Demonstrates: the four-table reconciliation model (reconciliation_run → reconciliation_pair → reconciliation_break). Breaks are classified into typed categories (PRICE, QUANTITY, MISSING_IN_ABOR, etc.) and linked to the holding entity via the pair. This replicates the daily break report that operations teams use to triage ABOR vs. SRDB discrepancies.
SELECT
rb.break_category,
e.legal_name AS holding_entity,
COUNT(*) AS break_count,
SUM(rb.break_amount_usd) AS total_break_usd
FROM reconciliation_break rb
JOIN reconciliation_pair rp ON rb.pair_id = rp.pair_id
JOIN reconciliation_run rr ON rp.run_id = rr.run_id
JOIN entity e ON rp.holding_entity_id = e.entity_id
WHERE rr.as_of_date >= '2025-10-01'
AND rr.as_of_date <= '2025-12-31'
GROUP BY rb.break_category, e.legal_name
ORDER BY rb.break_category, e.legal_name| break_category | holding_entity | break_count | total_break_usd |
|---|---|---|---|
| PRICE | SRAM Energy Haynesville SPV LLC | 1 | -$341,015.96 |
| QUANTITY | LongTail Re Ltd | 1 | $0.00 |
| MISSING_IN_ABOR | NYDIG LLC | 1 | $3,790,802.05 |
| CLASSIFICATION | SRAM SFR Tampa SPV LLC | 1 | $0.00 |
Demonstrates: instrument_entity_role, which captures non-ownership operational relationships between external entities and SRHG instruments. For wells, OPERATOR is the working-interest operator (e.g. Haynesville Operating Co LLC, Coterra, EQT). Filtering to role_type='OPERATOR' and a specific entity surfaces the cross-asset footprint of any counterparty.
SELECT
e.legal_name AS operator,
i.asset_class,
i.subtype,
i.status,
ier.effective_share_pct
FROM instrument_entity_role ier
JOIN instrument i ON ier.instrument_id = i.instrument_id
JOIN entity e ON ier.entity_id = e.entity_id
WHERE ier.role_type = 'OPERATOR'
AND e.legal_name = 'Haynesville Operating Co LLC'
ORDER BY i.asset_class, i.subtype| operator | asset_class | subtype | status | effective_share_pct |
|---|---|---|---|---|
| Haynesville Operating Co LLC | WELL | HORIZONTAL_GAS | ACTIVE | NULL |
| Haynesville Operating Co LLC | WELL | HORIZONTAL_GAS | ACTIVE | NULL |
| Haynesville Operating Co LLC | WELL | HORIZONTAL_GAS | ACTIVE | NULL |
Demonstrates: the time-series substrate (series + series_obs) joined back to instrument metadata. The "current vintage" filter keeps only the most recent derivation run per series (valid_to IS NULL + MAX(vintage)), ensuring stale re-derivations are excluded. This pattern is how downstream analytics always pull the authoritative version of a derived series.
WITH latest_vintage AS (
SELECT
so.series_id,
MAX(so.vintage) AS max_vintage
FROM series_obs so
JOIN series s ON so.series_id = s.series_id
JOIN instrument_well iw ON s.instrument_id = iw.instrument_id
WHERE iw.basin = 'HAYNESVILLE'
AND s.measure_code = 'NET_REVENUE_USD_MONTHLY'
AND so.valid_to IS NULL
GROUP BY so.series_id
)
SELECT
iw.api_number,
iw.basin,
iw.formation,
DATE_TRUNC('month', so.observation_ts)::DATE AS month,
so.value AS net_revenue_usd,
lv.max_vintage AS vintage
FROM latest_vintage lv
JOIN series_obs so ON so.series_id = lv.series_id
AND so.vintage = lv.max_vintage
JOIN series s ON s.series_id = so.series_id
JOIN instrument_well iw ON iw.instrument_id = s.instrument_id
ORDER BY iw.api_number, so.observation_ts| api_number | basin | formation | month | net_revenue_usd | vintage |
|---|---|---|---|---|---|
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-05-01 | -$11,158.47 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-06-01 | -$11,779.45 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-07-01 | -$12,574.70 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-08-01 | -$12,462.05 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-09-01 | -$13,707.37 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-10-01 | -$14,084.50 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-11-01 | -$12,958.28 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2021-12-01 | -$12,212.17 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2022-01-01 | -$13,329.42 | derivation_run_derive_v1_2026-05-27 |
| 42-203-99001-00-00 | HAYNESVILLE | HAYNESVILLE_SHALE | 2022-02-01 | -$13,425.51 | derivation_run_derive_v1_2026-05-27 |