Three columns in the same row of the same table all describe "how much comes back per unit". One holds a number near 0.92, the other two hold numbers near 1.00, and the median distance between them is 8.24 percentage points. Nobody wrote a comment explaining why, so every query that mixes them is silently wrong by that margin.
That is not a bug story. It is a story about what a numeric column promises: a scale, an alphabet of values, and a range. In ai_predictions all three were quietly broken in different ways.
Production context: 135 columns, 50,046 rows (2026-06-21 to 2026-11-26), 49,518 settled, 28,110 correct.
SELECT count(*) AS rows,
count(*) FILTER (WHERE settled) AS settled,
count(*) FILTER (WHERE hit) AS correct,
count(DISTINCT model_id) AS models
FROM ai_predictions;
rows | settled | correct | models
--------+---------+---------+--------
50046 | 49518 | 28110 | 4019
Promise one: the scale you declared
fair_home, fair_draw, fair_away are numeric(6,3) — three decimals. You would assume a third decimal exists because something needs it.
SELECT count(*) AS non_null,
count(*) FILTER (WHERE round(fair_home,2) <> fair_home) AS needs_third,
count(DISTINCT fair_home) AS distinct_home
FROM ai_predictions WHERE fair_home IS NOT NULL;
non_null | needs_third | distinct_home
----------+-------------+---------------
49305 | 0 | 1169
Zero rows out of 49,305 use the third decimal. The declared scale is one digit wider than the data has needed, on three columns, for five months — harmless at four bytes a row, but a hint that the type was chosen by habit rather than by specification.
The contrast sits in the same table: ah_v5_p_up is numeric(8,6), 28,211 nulls and 21,835 values spread over 8,414 distinct points. Neither choice is documented.
The consequence is arithmetic: 1,169 distinct home prices across 49,305 rows means the average price is shared by 42.2 rows. Any analysis treating the price triple as an identity is about to be wrong.
Promise two: the alphabet you will ever hold
confidence_calibrated is numeric(6,4) and is supposed to be the probability attached to the direction on that row. Here is its actual alphabet:
SELECT count(DISTINCT confidence_calibrated) AS distinct_values,
min(confidence_calibrated) AS lo, max(confidence_calibrated) AS hi
FROM ai_predictions WHERE confidence_calibrated IS NOT NULL;
SELECT confidence_calibrated AS value, count(*) AS rows
FROM ai_predictions WHERE confidence_calibrated IS NOT NULL
GROUP BY 1 ORDER BY 2 DESC LIMIT 4;
distinct_values | lo | hi
-----------------+--------+--------
51 | 0.4721 | 0.7295
value | rows
---------+-------
0.5596 | 12130
0.5516 | 9696
0.5990 | 9213
0.5337 | 8387
Fifty-one distinct values for 50,046 rows, and the top four cover 39,426 rows — 78.78% of the table. This is not a probability estimate; it is a 51-entry lookup table wearing a continuous type.
The obvious hypothesis is a lookup keyed on (confidence, direction_arity). Test it:
SELECT confidence, direction_arity, count(*) AS n,
count(DISTINCT confidence_calibrated) AS distinct_values
FROM ai_predictions WHERE confidence_calibrated IS NOT NULL
GROUP BY 1,2 HAVING count(DISTINCT confidence_calibrated) > 1
ORDER BY 4 DESC LIMIT 4;
Not a function of those two either: the query returns confidence 6 on single picks at the top, 6,983 rows over 32 distinct probabilities. Whatever the key is — model lineage, league, the calibration window at write time — it is not in the two columns a reader would guess, and it is not recorded on the row. A value you cannot reproduce from the row is a cached answer to a question nobody wrote down.
The alphabet also destroys the ordering the name promises:
| confidence | graded rows | mean calibrated | realized hit rate |
|---|---|---|---|
| 1 | 256 | 0.4724 | 46.09% |
| 3 | 8,721 | 0.5336 | 53.12% |
| 5 | 12,516 | 0.5596 | 55.74% |
| 7 | 4,400 | 0.6007 | 60.25% |
| 8 | 2,052 | 0.6539 | 65.69% |
| 9 | 550 | 0.7295 | 73.82% |
| 10 | 58 | 0.5693 | 58.62% |
Confidence 9 is the best-calibrated bucket in the table and also the last honest one. Confidence 10 sits 16.02 points below it, on 58 graded rows drawn from 53 different models — roughly one row per model, which is what you would expect if "10" is not a calibrated state but a rare output. Value 0.7295 occurs 550 times, precisely the number of confidence-9 rows, and inside confidence 9 it is the only value present: the mapping is a constant.
The rank test is mechanical: the maximum probability ever assigned at confidence 9 is 0.7295, and counting how many confidence-10 rows fall below it gives 63 out of 63. Every row at the highest integer confidence is less likely, by the table's own numbers, than the best row at the second-highest.
Promise three: the level, which is not a promise at all
Scale and alphabet are static. The third assumption is that the level tracks reality:
| month | rows | mean calibrated | realized rate | gap |
|---|---|---|---|---|
| 2026-06 | 2,735 | 0.6195 | 0.6230 | −0.35pp |
| 2026-07 | 2,637 | 0.6115 | 0.5089 | +10.26pp |
| 2026-08 | 164 | 0.5604 | 0.5793 | −1.89pp |
| 2026-09 | 9,757 | 0.5641 | 0.5931 | −2.90pp |
| 2026-10 | 21,886 | 0.5636 | 0.5615 | +0.21pp |
| 2026-11 | 12,867 | 0.5624 | 0.5356 | +2.68pp |
Weighted across the table the gap is +0.73pp, which looks excellent and is a lie of aggregation: only June (−0.35pp) and October (+0.21pp) are faithful. July is off by 10.26 points — the column claimed 61.15% and delivered 50.89%.
Then the level itself moves: between July and August the mean drops 5.11 points, from 0.6115 to 0.5604, on 164 rows. No realized rate explains a step that size — July realized 0.5089, August 0.5793. The column stepped away from July's reality and toward nothing in particular. Since September it has sat between 0.5624 and 0.5641 while realized performance wandered from 0.5356 to 0.5931.
A constant level with a drifting outcome is the signature of a lookup refitted once and then frozen — fine as an engineering choice, if the column is named for what it is and the refits are dated. Neither is true.
Two rows where the number is not small, it is absent
return_rate is numeric(5,4), max 0.9967, 1,345 distinct values. Two rows hold exactly 0.0000. Both belong to model 1, both at confidence 5, both calibrated to 0.5596; one graded correct, one not. Their stored prices are 2.290 / 3.570 / 3.520, and 1 / (1/2.290 + 1/3.570 + 1/3.520) = 0.9991. So arithmetic recovers 0.9991 for a row whose column says 0.0000. This is not precision loss but a sentinel — a handler that wrote zero and moved on — sitting in a field that is later averaged and summed. WHERE return_rate > 0.9 drops both rows without a warning.
The same table has an integer with a 1-to-10 range contract and exactly one row at 0: SELECT count(*) FROM ai_predictions WHERE confidence NOT BETWEEN 1 AND 10 returns 1. Nothing broke — its calibrated value is 0.5837 and it was graded correct — but the guard that should have caught it does not exist, and one row is how a range contract always starts: never violated wholesale, violated once and then twice.
Nulls are the same problem, quieter: fair_home is null on 741 rows (1.48%), and 246 of those have raw opening prices present — the input existed, the derived column did not.
The triple is not an identity
Group by the full price triple and 49,305 rows collapse to 21,264 groups:
WITH t AS (SELECT fair_home, fair_draw, fair_away, count(*) AS c
FROM ai_predictions WHERE fair_home IS NOT NULL GROUP BY 1,2,3)
SELECT count(*) g, count(*) FILTER (WHERE c>1) shared,
sum(c) FILTER (WHERE c>1) rows_shared, max(c) mx FROM t;
groups | shared_groups | rows_in_shared | largest
--------+---------------+----------------+---------
21264 | 8904 | 36945 | 120
36,945 rows — 74.93% — sit on a triple at least one other row also holds, and the largest group has 120 rows. Check what it is:
SELECT count(*) AS rows, count(DISTINCT match_id) AS fixtures,
count(DISTINCT model_id) AS models, min(created_at)::date AS first_write
FROM ai_predictions
WHERE fair_home = 1.810 AND fair_draw = 4.070 AND fair_away = 4.970;
rows | fixtures | models | first_write
------+----------+--------+-------------
120 | 1 | 120 | 2026-07-06
One fixture, 120 rows, 120 distinct models, all written the same day. Nothing is duplicated — these are 120 independent analyses of one match against a single price set — but the row-level consequence stands: (fair_home, fair_draw, fair_away) cannot serve as a dedupe key or a hash input. Deduping on it would collapse 8,904 groups and drop 28,041 rows.
Only 4,363 of the 21,264 groups span more than one fixture (max 25), so the collision is overwhelmingly within a fixture, driven by model fan-out rather than price granularity — and the same 74.93% supports both diagnoses.
What a contract looks like
None of the fixes needs an index or a rewrite; they need declarations.
ALTER TABLE ai_predictions
ADD CONSTRAINT confidence_range CHECK (confidence BETWEEN 1 AND 10) NOT VALID,
ADD CONSTRAINT return_rate_range CHECK (return_rate IS NULL OR return_rate BETWEEN 0.5 AND 1.0) NOT VALID,
ADD CONSTRAINT fair_positive CHECK (fair_home IS NULL OR fair_home > 1.0) NOT VALID;
COMMENT ON COLUMN ai_predictions.confidence_calibrated IS
'Lookup, 51 entries, refit 2026-08. Not a per-row estimate.';
NOT VALID is the point: it binds every future row while the one bad confidence and two bad return rates stay visible as a review queue instead of being silently backfilled.
Three habits
- Print the alphabet.
count(DISTINCT x)besidecount(*): 51 versus 50,046 instantly says whether you hold an estimate or a dictionary. - Never trust a declared scale. Check whether the last digit is ever non-zero. Zero out of 49,305 means the type is a wish, not a spec.
- Separate "shares a value" from "is a duplicate". The same 74.93% is a fan-out artefact or a data-quality disaster depending on one
count(DISTINCT match_id).
The unifying failure is not any single bad value. It is that four columns in one row can each be plausible and mutually inconsistent, because the schema recorded types and never recorded meanings. A numeric column without a unit, an alphabet and a range is not data; it is a number that happens to parse.
Analytics and research content. Not betting advice. 18+
本内容仅供数据分析与操作参考,不构成任何决策建议。