title: union not working as expected in PostgreSQL
body: <p>I Have a union query:</p>
  
  <pre><code>(SELECT
      to_char(createdatutc,'YYYY') as "Yr",
      to_char(createdatutc,'MM') as "Mh",
      count(postid) as Freq
  FROM conversations
  WHERE type = 'Post'
  GROUP BY Yr, Mh
  HAVING Yr = '2018')
  UNION
  (SELECT
      to_char(createdatutc,'YYYY') as "Yr",
      to_char(createdatutc,'MM') as "Mh",
      count(postid) as Freq
  FROM conversations
  WHERE type &lt;&gt; 'Post'
  GROUP BY Yr, Mh having Yr = '2018')
  ORDER BY  Yr, Mh
  </code></pre>
  
  <p>which is throwing the following error upon executing:</p>
  
  <blockquote>
    <p>org.postgresql.util.PSQLException: ERROR: column "conversations.createdatutc" must appear in the GROUP BY clause or be used in an aggregate function`</p>
  </blockquote>
  
  <p>However, If I run them individually they run properly , here createdatutc is a timestamp field</p>