Q:

Check if difference between current time and a stored time value is bigger than a fixed value

The setup: a number of devices (arduino, not that it matters) connect to my database to update their current state: voltage, temperature, etc... and last_update column. 
What i'm trying to do is know when a device goes offline.  Meaning when current_time-last_update is superior to let's say 10 seconds (constant value), i can update "device_state" to "offline"
What's the best optimal way to do that.  Best way i found is create a job that selects every minute or so all devices which last_update is older than 10 seconds.  Is there a better way? 
It's a monitoring system with a web frontend.  I need to know in real time (or almost real time) which devices are offline. 
Thanks

A:

You can implement this functionality using a view:
create view v_t as
    select t.*,
           ( last_update < now() - interval '10 second' ) as is_offline
    from t;

When you query the view, the column will automatically be updated. 
Many databases support computed columns.   Postgres is not yet one of them. 
There is also a method using a function that does something very similar (see here for details).