title: PostgreSQL - how do I create a window frame with a condition?
body: <p>Let's say I have the following table:</p>
  
  <pre><code>CREATE TABLE stock_prices (
    stock TEXT NOT NULL,
    date  DATE NOT NULL,
    price REAL NOT NULL,
    UNIQUE (stock, date)
  );
  </code></pre>
  
  <p>I want to calculate for each day, the highest price for each stock in the preceding 3-month window.</p>
  
  <p>I can't do a simple self join with <code>date - INTERVAL(3 'MONTH')</code> since my <code>stock_price</code> table has some "holes" for holidays and weekends. Similarly a naive window also does not work:</p>
  
  <pre><code>SELECT
    stock,
    date,  
    LAST_VALUE(price) OVER (PARTITION BY stock ORDER BY date ROWS 90 PRECEDING)
  FROM stock_prices
  </code></pre>
  
  <p>I almost want a window frame here with a condition based on the current row. Is that possible in PostgreSQL?</p>