Levels of Agentic Engineering
1
1
A stylized narrative of my experiences with Claude in the last 4 months
Six tables capture the full lifecycle from trade execution through risk reporting:
counterparty — legal entities you face (LEI, name)account — books/funds that hold positionsinstrument — master contract record per OTC dealtrade — individual fills that build positionsposition — end-of-day snapshots per accountgreek_risk — timestamped sensitivities per positionSupports swaps, forwards, options, CDS, swaptions, caps/floors, NDFs, and commodity derivatives.
-- Instruments carry product-specific nullable fields
CREATE TABLE instrument (
instrument_type instrument_type NOT NULL,
notional NUMERIC(20,4) NOT NULL,
maturity_date DATE NOT NULL,
strike NUMERIC(20,8), -- options only
fixed_rate NUMERIC(10,6), -- swaps / CDS
floating_index TEXT, -- e.g. 'SOFR'
counterparty_id BIGINT NOT NULL REFERENCES ...
);
-- Greek snapshots track risk evolution over time
CREATE TABLE greek_risk (
position_id BIGINT NOT NULL,
as_of_timestamp TIMESTAMPTZ NOT NULL,
delta NUMERIC(20,6),
gamma NUMERIC(20,6),
vega NUMERIC(20,6),
theta NUMERIC(20,6),
dv01 NUMERIC(20,6),
cs01 NUMERIC(20,6),
pricing_model TEXT,
model_params JSONB -- full reproducibility
);client_id migration example, it chose a non-nullable column with an empty string defaultdsl column in the custom_datapoint table can refer to rows in the datapoint table. add a join table and check constraint to capture this mapping and ensure that no rows get deleted from datapoint if they are referenced by the DSL definition of a row in custom_datapoint.”CREATE TABLE datapoint (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE custom_datapoint (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL,
-- references datapoint rows,
-- but only as free text!
dsl TEXT NOT NULL
-- e.g. 'price("AAPL") * 2
-- + price("GOOG")'
);
-- No FK possible — the references
-- are buried inside the DSL string-- Join table: extracted references from DSL text
CREATE TABLE custom_datapoint_reference (
custom_datapoint_id BIGINT NOT NULL REFERENCES custom_datapoint(id),
datapoint_id BIGINT NOT NULL REFERENCES datapoint(id) RESTRICT,
PRIMARY KEY (custom_datapoint_id, datapoint_id)
);
-- Trigger: parse DSL and populate join table on insert/update
CREATE FUNCTION extract_dsl_references()
RETURNS TRIGGER AS $$
BEGIN
DELETE FROM custom_datapoint_reference
WHERE custom_datapoint_id = NEW.id;
INSERT INTO custom_datapoint_reference
(custom_datapoint_id, datapoint_id)
SELECT NEW.id, d.id FROM datapoint d
WHERE NEW.dsl ~ ('\m' || d.name || '\M');
-- regex word-boundary match (much more complicated in my version)
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_extract_dsl_refs
AFTER INSERT OR UPDATE OF dsl ON custom_datapoint
FOR EACH ROW EXECUTE FUNCTION extract_dsl_references();pg_restore_relation_stats() and pg_restore_attribute_stats()SELECT pg_restore_attribute_stats(
'schemaname', 'public',
'relname', 'test_orders',
'attname', 'status',
'inherited', false::boolean,
'null_frac', 0.0::real,
'avg_width', 9::integer,
'n_distinct', 5::real,
'most_common_vals',
'{delivered,shipped,cancelled,
pending,returned}'::text,
'most_common_freqs',
'{0.95,0.015,0.015,
0.015,0.005}'::real[]
);1 2
What have your biggest learnings been with Claude + Postgres been so far? Let’s discuss!
pgwhalen.com/early-learnings-with-postgres-and-claude