fix(analytics): wrap max_date in ANY_VALUE() in get_weather_stress_latest

DuckDB requires all selected columns to be aggregate expressions when there
is no GROUP BY. latest.max_date is a scalar CTE value but still needs
ANY_VALUE() wrapping to satisfy the binder.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-26 19:50:27 +01:00
parent 6461c58957
commit d3c9d95386

View File

@@ -677,7 +677,7 @@ async def get_weather_stress_latest() -> dict | None:
FROM serving.weather_daily FROM serving.weather_daily
) )
SELECT SELECT
latest.max_date AS observation_date, ANY_VALUE(latest.max_date) AS observation_date,
ROUND(AVG(w.crop_stress_index), 1) AS avg_crop_stress_index, ROUND(AVG(w.crop_stress_index), 1) AS avg_crop_stress_index,
MAX(w.crop_stress_index) AS max_crop_stress_index, MAX(w.crop_stress_index) AS max_crop_stress_index,
COUNT(*) FILTER (WHERE w.crop_stress_index > 20) AS locations_under_stress, COUNT(*) FILTER (WHERE w.crop_stress_index > 20) AS locations_under_stress,