fix(discovery): use interval multiplication for forward-window query

pgx cannot implicitly encode int arg into text for the `$1 || ' month'`
concatenation pattern (error: "unable to encode 12 into text format for
text (OID 25): cannot find encode plan"). Multiplication with a known
interval works directly with the int parameter and is semantically
equivalent.

Discovered during the T19 smoke test — the tick endpoint returned 500
on every call before this fix.
This commit is contained in:
2026-04-18 08:08:27 +02:00
parent 31ce937f55
commit b222d5fbc8

View File

@@ -47,7 +47,7 @@ func (r *pgRepository) PickStaleBuckets(ctx context.Context, forwardMonths, limi
SELECT id, land, region, year_month, last_queried_at, coalesce(last_error, ''), created_at
FROM discovery_buckets
WHERE year_month >= to_char(date_trunc('month', now()), 'YYYY-MM')
AND year_month <= to_char(date_trunc('month', now()) + ($1 || ' month')::interval, 'YYYY-MM')
AND year_month <= to_char(date_trunc('month', now()) + ($1 * interval '1 month'), 'YYYY-MM')
AND (last_queried_at IS NULL OR last_queried_at < now() - interval '7 days')
ORDER BY last_queried_at NULLS FIRST, year_month
LIMIT $2`