I wrote a function called insert_offset_data(text, double precision)
as the following:
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;
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?
Add this:
DELETE FROM tempoffset WHERE ts_insert < now()-'1 hour'::interval;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With