Just spotted this question although it has been for 6 years.
LAST() -> LAST_VALUE(). Also you should provide the complete error log.
https://www.postgresql.org/docs/17/functions-window.html#FUNCTIONS-WINDOW