title: is postgres BEFORE UPDATE trigger atomic?
body: <p>I trying to do conditional UPDATE trigger. It should update row only if certain condition, depending on old row data, is met (I know I can simply do UPDATE ... WHERE ... but from various reasons trigger is the way to go for us):</p>
  <pre><code>CREATE
  OR REPLACE FUNCTION update_only_with_higher_timestamp()
    RETURNS trigger LANGUAGE plpgsql AS
  $$BEGIN
   IF
  NEW.timestamp &lt; OLD.timestamp THEN
      RETURN OLD;
  END IF;
  
  RETURN NEW;
  END;$$;
  
  
  CREATE TRIGGER avoid_updating_rows_with_lower_timestamp
      BEFORE UPDATE
      ON table
      FOR EACH ROW
      EXECUTE PROCEDURE update_only_with_higher_timestamp();
  
  </code></pre>
  <p>My question is, is this operation atomic? Or could it happen that I base that condition on old data which might not be the most up to date at the time?</p>
  <p>Thanks for the answer!</p>