title: How can I select one row for each week in a date range that spans more than a year?
body: <p>In my postgreSQL data base, I have a table with columns of dates and prices. ('transdate' and 'price')</p>
  
  <p>I would like to form a query which selects one row for each week over a date range which spans more than one year.</p>
  
  <p>From another question/answer here, I implemented this code which works for date ranges of less than a year:</p>
  
  <pre><code>;with cte as  
  (  
    select *,  
    row_number() over (partition by Extract (week from transdate) order by transdate desc) as rn   
    from "tablename" where transdate between '06-01-1999' and '06-01-1999'::timestamp + `'50 week'::interval  
  )  
  select transdate, price from cte where rn = 1 order by transdate;
  </code></pre>
  
  <p>However, when I extend the interval greater than 50 weeks, it still only selects a max of 12 months.</p>
  
  <p>How can I re-write this code to select one date/price from every week in the range?</p>