title: How to use a counter in a Postgresql function loop when generating a timestamp type for each iteration
body: <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION inserts_table_foo(startId INT,
                                           endId INT,
                                           stepTimeZone INT default 0,
                                           period INT default 0) RETURNS void AS
  $$
  DECLARE
  
      nameVar TEXT;
      dateVar TIMESTAMP;
  
  begin
      for idVar in startId..endId
          loop
  
              nameVar := md5(random()::text);
              dateVar :=
                      (now()::timestamp with time zone +
                       make_interval(hours := stepTimeZone) +
                       make_interval(days := period)
                          );
  
              period := period + 1;
  
              insert into foo(id, name, data) values (idVar, nameVar, dateVar);
  
          end loop;
  end ;
  $$ LANGUAGE plpgsql;
  </code></pre>
  <p>Unfortunately, the <em>variable</em> -&gt; <strong>period</strong>, does not work as intended.  I assumed that the counter would increase by 1 and each time, the <em><strong>date generation</strong></em> would be different, but in fact, the date turns out to be the same for the entire duration of the cycle.</p>
  <p>How to make the date, for each iteration, be generated anew? This won't do here</p>
  <pre class="lang-sql prettyprint-override"><code>generate_series ( TIMESTAMP WITHOUT TIME ZONE '2022-01-01', CURRENT_DATE, '1 day' )
  </code></pre>
  <p>because, you need to bet <strong>100,000,000</strong> records, in a table where the date field can be in the table in several places (<strong>dateStart, dateEnd, startDateReg</strong>, etc.) and are placed out of order. Therefore, I want to make a function that accepts a number of variables, according to which I can set the periods of the <strong>generated values</strong>, in this example, this is the <strong>date and time</strong>.</p>
  <p>I would like to clearly see which variable the value comes into and also see the code for inserting this value into the table (that is, using the <strong>INSERT into</strong> entry .....)</p>
  <p>What is the problem here and how could it be solved ?</p>