CREATE OR REPLACE FUNCTION set_updated_at() RETURNS trigger AS $$ BEGIN IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at) THEN NEW.updated_at := current_timestamp; END IF; RETURN NEW; END $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION set_updated_at_ignore_downloads() RETURNS trigger AS $$ BEGIN IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at AND NEW.downloads = OLD.downloads) THEN NEW.updated_at := current_timestamp; END IF; RETURN NEW; END $$ LANGUAGE plpgsql;