title: Sum column value and group dates by month with Postgres
body: <p>I've got a table in my Postgres DB that looks something like this:</p>
  
  <pre><code>date          duration
  2018-05-10      10
  2018-05-12      15
  2018-06-01      10
  2018-06-02      20
  2019-01-01      5
  2019-01-02      15
  2019-04-01      10
  </code></pre>
  
  <p>And I wish to sum the values for each month and group them by year, month and, month number into something like this:</p>
  
  <pre><code>year    month    month_number   monthly_sum
  2018    May         5              25
  2018    June        6              30
  2019    Jan         1              20
  2019    Apr         4              10
  </code></pre>
  
  <p>And ended up with a query that looks like this:</p>
  
  <pre><code>SELECT 
    to_char(date_trunc('month', date), 'YYYY') AS year,
    to_char(date_trunc('month', date), 'Mon') AS month,
    to_char(date_trunc('month', date), 'MM') AS month_number,
    sum(duration) AS monthly_sum
  FROM timesheet 
  GROUP BY year, month, month_number
  </code></pre>
  
  <p>And it works just fine, my question is: is this query considered bad? Will it affect performance if I have like.. 100k rows? I heard using to_char is inferior to date_trunc, which is what I tried to avoid here, I just wrapped the date_trunc in a to_char. 
  Also, having three values in a <code>GROUP BY</code> clause, does it affect anything?</p>