title: PostgreSQL - Deleting data that are older than an hour, and then inserting new data to the same table
body: <p>I wrote a function called <code>insert_offset_data(text, double precision)</code> as the following:</p>
  
  <pre><code>BEGIN
  INSERT INTO tempoffset(id, location, offset_factor, ts_insert) 
  VALUES (uuid_generate_v4(), location_in, offset_in, (now() at time zone 'utc'));
  
  RETURN 1;
  END;
  </code></pre>
  
  <p>However, since this function is used in an API call whenever users insert data from an iOS application, I would love to delete data that are older than 1 hour in the table before inserting new data to it since the iOS application doesn't take into account data that are older than an hour. How do I write code to delete old data before I insert a new data in the same function?</p>