title: Use function within generate_series
body: <p>I'm new using postgres and the PL/pgSQL. My code is below . I want to modify my code to compare value of variable with the generate series function like:</p>
  <pre><code>if variable == '2019-08-22' then 
  generate_series(date_trunc('day', s.beg), date_trunc('day', 
  least(s.enddate, current_date)), interval '1 day') gs(date)
  else 
  generate_series(date_trunc('day', s.beg), date_trunc('day', 
  least(s.enddate, $$var$$)), interval '1 day') gs(date)
  </code></pre>
  <p>Below my code.
  Any suggestions is highly appreciated.</p>
  <pre><code>INSERT INTO $$||table_name||$$
  (number_, date, type, minutes)
   select
       number_, gs.date,
        (case
              when trim(string) ~ '^XYZ[0-9]$'
         then 'ALPHANUMERIC'
        end) as type,
  sum(extract(epoch from (least(s.enddate, gs.date + interval '1 day' -
                             greatest(s.beg, gs.date)
                            )
                ) / 60) as minutes
  from table s cross join lateral
  generate_series(date_trunc('day', s.beg), date_trunc('day', 
  least(s.enddate, current_date)), interval '1 day') gs(date) 
  </code></pre>