title: Postgres/Redshift: Extract Quarter and Year from date column for a group by in one call?
body: <p>I was wondering if there was a way to extract a year and Quarter from a date column in one call from Redshift/Postgres DB in order for me to group by on them?</p>
  
  <p>Since query speed is very important to me, I currently have the year and column as two columns along with the date which I am not happy about, as I have this information in the date column however they make queries almost twice as fast if I join on them versus using two <code>extract()</code> calls on the date to get the year and quarter. </p>
  
  <p>e.g </p>
  
  <pre><code>Select SUM(some_column), 
  EXTRACT(YEAR FROM the_date) as year_date,
  EXTRACT(YEAR FROM the_date) as q_date
  FROM table
  Group by year_date, q_date;
  </code></pre>
  
  <p>vs </p>
  
  <pre><code>Select SUM(some_column), 
  year_date,
  q_date
  FROM table
  Group by year_date, q_date;
  </code></pre>
  
  <p>I would be looking for something like this:</p>
  
  <pre><code>Select SUM(some_column), 
  extract(Year | Quarter from the _date) AS year_q
  FROM table
  Group by year_q;
  </code></pre>
  
  <p>I tried the to_char method but it's slower than both options above.</p>
  
  <p>Thanks  </p>