Downsampling to (eg) "last result on Sunday night"
You can select only those rows that are less than five minutes before midnight:
... WHERE
      -- less than 5 nimutes before midnight
      TIME '24:00:00' - CAST(time AS time) &lt; INTERVAL '5 minutes'
      -- on a Sunday
      AND extract (dow FROM time) = 0