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.

Query 1What does SRHG own and what is it worth as of 2025-12-31, by asset class, by entity?

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_classholding_entitytotal_market_value_usd
WELLSRAM Energy Haynesville SPV LLC$1,156,187.48
WELLSRAM Energy Marcellus SPV LLC$1,365,676.60
CRYPTO_DERIVNYDIG LLC$10,954,327.92

Query 2What's LTRe's indirect ownership through SRAM funds as of 2025-12-31?

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_nameasset_classinstrument_subtypeposition_counttotal_attributed_value_usd
LongTail Re LtdCRYPTO_DERIVCME_FUT2$376,907.93
LongTail Re LtdCRYPTO_DERIVDERIBIT_OPT2$88,651.01
LongTail Re LtdSFR_PORTFOLIOMSA_PORTFOLIO3$116,868,571.67
LongTail Re LtdTREATYCASUALTY_QS4-$8,815,090.41
LongTail Re LtdTREATYCAT_XOL3-$1,116,164.38
LongTail Re LtdWELLHORIZONTAL_GAS6$643,075.34

Query 3aWhat did we think we owned on 2024-06-15, given what we knew on 2024-06-30?

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_idas_of_datequantityquantity_unitmarket_value_usdtxn_fromtxn_to
00000000-0000-0000-0401-0000000000012024-06-151,000CONTRACTS$5,100,000.002024-06-16T05:00:00-04:002024-06-30T05:00:00-04:00

Query 3bWhat do we know NOW about what we owned on 2024-06-15?

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_idas_of_datequantityquantity_unitmarket_value_usdtxn_fromtxn_to
00000000-0000-0000-0401-0000000000022024-06-151,010CONTRACTS$5,151,000.002024-06-30T05:00:00-04:00NULL

Query 4Which positions break against ABOR for 2025-Q4, by break category, by entity?

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_categoryholding_entitybreak_counttotal_break_usd
PRICESRAM Energy Haynesville SPV LLC1-$341,015.96
QUANTITYLongTail Re Ltd1$0.00
MISSING_IN_ABORNYDIG LLC1$3,790,802.05
CLASSIFICATIONSRAM SFR Tampa SPV LLC1$0.00

Query 5Find all instruments operated by entity X across asset classes.

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
operatorasset_classsubtypestatuseffective_share_pct
Haynesville Operating Co LLCWELLHORIZONTAL_GASACTIVENULL
Haynesville Operating Co LLCWELLHORIZONTAL_GASACTIVENULL
Haynesville Operating Co LLCWELLHORIZONTAL_GASACTIVENULL

Query 6Show monthly net revenue series for all wells in the Haynesville basin, current vintage.

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_numberbasinformationmonthnet_revenue_usdvintage
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-05-01-$11,158.47derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-06-01-$11,779.45derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-07-01-$12,574.70derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-08-01-$12,462.05derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-09-01-$13,707.37derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-10-01-$14,084.50derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-11-01-$12,958.28derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2021-12-01-$12,212.17derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2022-01-01-$13,329.42derivation_run_derive_v1_2026-05-27
42-203-99001-00-00HAYNESVILLEHAYNESVILLE_SHALE2022-02-01-$13,425.51derivation_run_derive_v1_2026-05-27
+ 148 more rows