Snowflake BITXOR_AGG can hide a warning that appeared twice
XOR reports whether each flag appeared an odd number of times. For a daily report that asks which warnings ever appeared, use a bitwise OR and keep missing observations visible.
Ask a SQL agent, “Which warnings appeared in any import today?” and the important word is any. If each run stores its warnings in an integer bitmask, the query needs to keep a bit set whenever at least one run reported it. Snowflake’s BITOR_AGG does that. BITXOR_AGG instead sets a bit only when an odd number of rows have it set. Two real occurrences can disappear from the summary.
A three-run example
Suppose bit value 1 means “schema drift” and bit value 2 means “late source.” In this synthetic batch, one run reported schema drift, one reported both warnings, and one produced no mask. The following expected results are derived from Snowflake’s documented rules, not from a live warehouse run.
WITH runs AS (
SELECT column1::NUMBER(38,0) AS warning_mask
FROM VALUES (1), (3), (NULL)
)
SELECT BITXOR_AGG(warning_mask) AS odd_occurrence_mask,
BITOR_AGG(warning_mask) AS ever_seen_mask,
COUNT(*) AS run_count,
COUNT(warning_mask) AS reported_mask_count
FROM runs;
The XOR result is 2: the schema-drift bit is present in both 1 and 3, so it cancels, while the late-source bit occurs once. The OR result is 3, preserving both warnings. In a batch with masks 1 and 1 alone, XOR would return 0 even though every run reported schema drift. Snowflake documents that DISTINCT has no effect on BITXOR_AGG; adding the keyword is not a fix.
Don’t turn missing telemetry into a clean bill of health
Both aggregates ignore NULL inputs and return NULL if all inputs are NULL or the group is empty. If your telemetry uses 0 for a run that explicitly reported no warnings and NULL for a run that supplied no mask, keep that distinction in the result. In the example, show that the mask summarizes two reporting runs out of three. A zero OR mask from those two runs would say nothing about the third.
For a text-to-SQL regression test, include two runs with the same flag, a run with a zero mask, and an all-NULL group. Check the generated answer as well as the SQL: “ever seen,” “seen an odd number of times,” and “not observed” are three different claims.
sources
- Snowflake SQL reference: BITXOR_AGGdocs.snowflake.com
- Snowflake SQL reference: BITOR_AGGdocs.snowflake.com
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