DuckDB can tell a failed run with no error message from an unknown outcome
If run outcomes are stored as a tagged UNION, count the failure tag rather than the error text. A four-row test shows why the two counts differ.
When a query agent is asked how many jobs failed, counting the error messages can give the wrong answer. In DuckDB, a column of the tagged UNION type can record a failed outcome even when its error message is NULL. The tag tells you the outcome; the value inside it tells you what was recorded about that outcome. This is a data type, not the SQL UNION operator.
The two counts answer different questions
DuckDB’s union_extract returns NULL if the requested member isn’t selected. It also gives you NULL if that member is selected but its payload is null. So extracting failed and looking only at the resulting strings cannot distinguish a success from a failure with no error text. union_tag reads the selected member instead.
Here is a four-row example run by the desk in DuckDB 2.0.0. The rows represent a failure with a message, a failure without one, a success, and a missing outcome:
WITH runs(outcome) AS (
VALUES
(CAST(union_value(failed := 'timeout') AS UNION(ok VARCHAR, failed VARCHAR))),
(CAST(union_value(failed := NULL::VARCHAR) AS UNION(ok VARCHAR, failed VARCHAR))),
(CAST(union_value(ok := 'done') AS UNION(ok VARCHAR, failed VARCHAR))),
(NULL::UNION(ok VARCHAR, failed VARCHAR))
)
SELECT count(*) AS runs,
count(union_extract(outcome, 'failed')) AS with_error_text,
count(*) FILTER (WHERE union_tag(outcome) = 'failed') AS failed_runs,
count(*) FILTER (WHERE outcome IS NULL) AS unknown_outcomes
FROM runs;
| Runs | With error text | Failed runs | Unknown outcomes |
|---|---|---|---|
| 4 | 1 | 2 | 1 |
Give the metric a test that distinguishes the two
If a semantic model or SQL agent exposes both measures, label them separately: failed runs for the tag count and failures with error text for the payload count. In a regression test, include at least one failure with a null payload and one entirely null outcome. A fixture where every failure has a message would let the wrong query pass. Apply the same distinction to a failure-rate denominator: decide whether unknown outcomes belong in it, rather than treating them as successes by default.
sources
- DuckDB 2.0 documentation: Union Typeduckdb.org
- DuckDB 2.0 documentation: Union Functionsduckdb.org
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026