title: multiple named windows in a postgres query
body: <p>The <a href="https://www.postgresql.org/docs/11/sql-select.html" rel="nofollow noreferrer">postgres docs</a> specify a window definition clause thus:</p>
  
  <pre><code>[ WINDOW window_name AS ( window_definition ) [, ...] ]
  </code></pre>
  
  <p>The <strong>[,...]</strong> specifies that multiple windows are possible. I find nothing else in the docs to confirm or deny it's possible. How do I make this work?</p>
  
  <p>In this query, I can use either window clause on its own but I can't use both even though the syntax follows the spec:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select q.*
  , min(value) over w_id as min_id_val
  --, min(value) over w_kind as min_kind_val
  from (
      select 1 as id, 1 as kind, 3.0 as value
      union select 1, 2, 1.0
      union select 2, 1, 2.0
      union select 2, 2, 0.5
  ) as q
  window w_id as (partition by id)
  -- , 
  -- window w_kind as (partition by kind)
  </code></pre>
  
  <p>I can get the technical effect by not using window definitions, but that gets tiresome for a complex query where windows are re-used:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select q.*
  , min(value) over (partition by id) as min_id_val
  , min(value) over (partition by kind) as min_kind_val
  from (
      select 1 as id, 1 as kind, 3.0 as value
      union select 1, 2, 1.0
      union select 2, 1, 2.0
      union select 2, 2, 0.5
  ) as q
  </code></pre>