tom
tom

Reputation: 2357

A trigger that detects that an UPDATE wouldn't change a row

I wrote the following trigger:

CREATE FUNCTION trig_func() RETURNS trigger AS $$
  BEGIN
    IF NEW = OLD
    THEN -- update would do nothing, doing something...
    END IF;
    RETURN NEW;
  END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trig BEFORE UPDATE ON some_table
  FOR EACH ROW EXECUTE PROCEDURE trig_func();

It makes it clear what I'd like to achieve, but what is the proper thing to put in place of NEW = OLD?

Upvotes: 0

Views: 27

Answers (1)

user330315
user330315

Reputation:

The is distinct from operator can compare complete rows and will handle nulls correctly.

So you want

if new is not distinct from old then 
   ...
end if;

Upvotes: 2

Related Questions