title: Set-returning functions are not allowed in CASE in postgreSQL
body: <p>I am trying to run this query was able to till some time ago. I don't know what went wrong and I started getting this error now?</p>
  
  <p><code>Your database returned: ERROR: set-returning functions are not allowed in CASE Hint: You might be able to move the set-returning function into a LATERAL FROM item.</code></p>
  
  <p>My query:</p>
  
  <pre><code>SELECT distinct
  (CASE
  WHEN {PERIOD} = 'Previous Quarter' AND pto.pto_start_date &lt; (date_trunc('quarter', now() - INTERVAL '1 month') + INTERVAL '1 month')::date AND pto.pto_end_date &gt;= (date_trunc('quarter', now() - INTERVAL '1 month') + INTERVAL '1 month')::date
  THEN generate_series(pto.pto_start_date, pto.pto_end_date, '2 day'::interval)
  WHEN {PERIOD} = 'Current Quarter' AND pto.pto_start_date &lt; (date_trunc('quarter', now() - INTERVAL '1 month') + INTERVAL '1 month')::date AND pto.pto_end_date &gt;= (date_trunc('quarter', now() - INTERVAL '1 month') + INTERVAL '1 month')::date
  THEN generate_series(pto.pto_start_date, pto.pto_end_date, '1 day'::interval)
  ELSE
  generate_series(pto.pto_start_date, pto.pto_end_date, '1 day'::interval)
  END) AS dt
  FROM cust_pto pto
  </code></pre>
  
  <p>Start dates and end Dates:</p>
  
  <p><a href="https://i.stack.imgur.com/X2vIV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2vIV.png" alt="enter image description here"></a></p>
  
  <p>What has gone wrong?</p>