There is a query with a Gap Lock used at MySQL/InnoDB:
SELECT id, time, count
FROM table_a
WHERE time
BETWEEN DATE_SUB(NOW(), INTERVAL 24 HOUR)
AND NOW()
FOR UPDATE
It locks the time range and returns a recent record if present (during last 24 hrs).
If not - the session still owns a lock over the duration of last 24 hours to safely insert a new record.
Is is possible to make the same gap lock for entire 24 hours duration (even if there are no records) in PostgreSQL?