CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$
	DECLARE
		channel_name varchar DEFAULT (TG_TABLE_NAME || '_changes');
	BEGIN
		IF TG_OP = 'INSERT' THEN
			PERFORM pg_notify(channel_name, '{"id": "' || NEW.id || '"}');
			RETURN NEW;
		END IF;
		IF TG_OP = 'DELETE' THEN
			PERFORM pg_notify(channel_name, '{"id": "' || OLD.id || '"}');
			RETURN OLD;
		END IF;
		IF TG_OP = 'UPDATE' THEN
			PERFORM pg_notify(channel_name, '{"id": "' || NEW.id || '"}');
			RETURN NEW;
		END IF;
	END;
	$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS users_changes_trigger on users;
CREATE TRIGGER users_changes_trigger AFTER INSERT OR UPDATE OR DELETE ON users FOR EACH ROW EXECUTE PROCEDURE notify_trigger();	