Skip to content

Commit 30521da

Browse files
authored
fix(sql): Correct GetLatestForcast logic (#118)
1 parent 42ef300 commit 30521da

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/server/postgres/sql/queries/predictions.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ INSERT INTO pred.predicted_generation_values (
111111
SELECT DISTINCT ON (fr.forecaster_name)
112112
f.forecast_uuid,
113113
f.init_time_utc,
114+
f.created_at_utc,
114115
f.source_type_id,
115116
f.geometry_uuid,
116117
fr.forecaster_id,
@@ -122,17 +123,19 @@ FROM pred.forecasters AS fr
122123
forecast_uuid,
123124
init_time_utc,
124125
source_type_id,
125-
geometry_uuid
126+
geometry_uuid,
127+
UUIDV7_EXTRACT_TIMESTAMP(forecast_uuid) AS created_at_utc
126128
FROM pred.forecasts
127129
WHERE geometry_uuid = $1
128130
AND source_type_id = $2
129131
AND forecaster_id = fr.forecaster_id
130132
AND init_time_utc
131133
<= sqlc.arg(pivot_timestamp)::TIMESTAMP - MAKE_INTERVAL(mins => sqlc.arg(horizon_mins)::INTEGER)
134+
-- AND target_period @> (sqlc.arg(pivot_timestamp)::TIMESTAMP)
132135
ORDER BY init_time_utc DESC
133136
LIMIT 1
134137
) AS f
135-
ORDER BY fr.forecaster_name ASC;
138+
ORDER BY fr.forecaster_name ASC, f.init_time_utc DESC;
136139

137140
-- name: ListForecasts :many
138141
/* ListForecasts retrieves all the forecasts for a given location, source type, and forecaster

0 commit comments

Comments
 (0)