-- Notification automatique lors de l'insertion d'un bloc
CREATE OR REPLACE FUNCTION notify_new_block()
RETURNS TRIGGER AS $$
BEGIN
  PERFORM pg_notify('new_block', NEW.block_id::text);
  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_notify_block
AFTER INSERT ON blocks
FOR EACH ROW
EXECUTE FUNCTION notify_new_block();