Try to write the query for each item should be archived if N hours (auto_archive_h in the table) wasn't updated. For mark item as archived need set archived to TURE and archived_at to now. But if auto_archive_h is NULL or updated_at is NULL not touching in the query, just pass.
Saturday and Sunday do not count as time for archived.
I got an issue in the WHERE condition. How to calculate the difference in hours and compare it with an auto_archive_h?
Table:
CREATE TABLE items
(
id BIGSERIAL PRIMARY KEY,
updated_at TIMESTAMP,
auto_archive_h INT,
archived BOOLEAN NOT NULL DEFAULT FALSE,
archived_at TIMESTAMP
);
Query:
UPDATE items
SET archived = TRUE, archived_at = now()
WHERE ?issue_here?
That something like to_hours(now() - updated_at) > auto_archive_h but with wrire syntax.
Help me to complete the query. Thank You.
where updated_at <= current_timestamp - make_interval(hours => auto_archive_h)auto_archive_h. Or I misunderstand your idea.