Plpgsql (Postgres) function for sanity check
It seems you just need the query:

UPDATE sensors 
 SET seconds=(SELECT sensors.starttime-"timestamp" FROM secure_sanity
              WHERE id=*id*)
   WHERE seconds=0;


For that, it's overkill to write a plpgsql function.

Or if you really want one, just replace this *id* by a function parameter put the above UPDATE query inside a CREATE FUNCTION / BEGIN / END block.