fix: PostgreSQL date subtraction in historical value query
**Error:** function pg_catalog.extract(unknown, integer) does not exist HINT: No function matches the given name and argument types. **Problem:** In PostgreSQL, date - date returns INTEGER (days), not INTERVAL. EXTRACT(EPOCH FROM integer) fails because EPOCH expects timestamp/interval. **Solution:** Changed from: ORDER BY ABS(EXTRACT(EPOCH FROM (date - '2026-01-01'))) To: ORDER BY ABS(date - '2026-01-01'::date) This directly uses the day difference (integer) for sorting, which is exactly what we need to find the closest date. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1c7b5e0653
commit
7ffa8f039b
|
|
@ -713,7 +713,7 @@ def _get_historical_value_for_goal_type(conn, profile_id: str, goal_type: str, t
|
||||||
FROM {source_table}
|
FROM {source_table}
|
||||||
WHERE profile_id = %s
|
WHERE profile_id = %s
|
||||||
AND {date_col} BETWEEN %s AND %s
|
AND {date_col} BETWEEN %s AND %s
|
||||||
ORDER BY ABS(EXTRACT(EPOCH FROM ({date_col} - %s::date)))
|
ORDER BY ABS({date_col} - %s::date)
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
""", (
|
""", (
|
||||||
profile_id,
|
profile_id,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user