How to use a ring data structure in window functions
Use COALESCE like @Justin provided. With first_value() / last_value() you need to add an ORDER BY clause to the window definition or the order is undefined. You just got lucky in the example, because the rows happen to be in order right after creating the dummy table. Once you add ORDER BY, the default window … Read more