Snowflake LAST_VALUE can pull a future reading into a historical report
An explicit frame ending at the current row keeps a forward fill from using observations that come later in the series.
A request like “carry the last known reading forward for each device” gives a SQL assistant two jobs: put the observations in order and limit which observations each row can see. In Snowflake, ORDER BY inside LAST_VALUE does the first job, but it does not do the second. The Snowflake reference says that without an explicit frame, LAST_VALUE uses the entire partition, from UNBOUNDED PRECEDING to UNBOUNDED FOLLOWING. A later measurement can therefore appear in a report row for an earlier time.
Run the same fill with two different frames
Consider one device with a reading of 10 at 09:00, a missing reading at 09:05 and a reading of 20 at 09:10. The query below illustrates the two outcomes implied by the documented frame and IGNORE NULLS behavior. The data are synthetic; the outputs are derived from the documentation, not an independent Snowflake run.
WITH readings AS (
SELECT column1 AS minute_of_day, column2 AS reading
FROM VALUES (540, 10), (545, NULL), (550, 20)
)
SELECT minute_of_day, reading,
LAST_VALUE(reading) IGNORE NULLS OVER (
ORDER BY minute_of_day
) AS whole_partition,
LAST_VALUE(reading) IGNORE NULLS OVER (
ORDER BY minute_of_day
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS known_at_that_row
FROM readings
ORDER BY minute_of_day;
The whole-partition expression yields 20 on all three rows. With a frame ending at the current row, the values are 10, 10 and 20. The distinction is clearest at 09:05: the latest non-null reading in the full series is 20, but the latest non-null reading at that point is 10. IGNORE NULLS skips missing values within the chosen frame; it does not set the frame. Snowflake documents that the default is RESPECT NULLS, so specify IGNORE NULLS when a null means a missing observation rather than a reset.
What to review in generated SQL
For multiple devices, partition by device. If timestamps tie, use a tie-breaker that reflects the intended event order: Snowflake notes that results are fully deterministic only when the window ordering keys make each row unique. A useful regression fixture is a gap followed by a different reading. The historical row should retain its prior value after the later reading is added. If the report is meant to reflect what was actually available at the time and readings can arrive late, check the availability cutoff separately; a frame over event time alone does not express that requirement.
sources
- Snowflake SQL reference: LAST_VALUEdocs.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