title: Any way to monitor Postgresql query changes in realtime using LISTEN & NOTIFY (or NodeJS)?
body: <p>So I have a custom Postgresql query that retrieves all rows within a specified longitude latitude radius, like so:</p>
  
  <pre><code>SELECT *, 
  earth_distance(ll_to_earth($1,$2), ll_to_earth(lat, lng)) as distance_metres
  FROM RoomsWithUsers
  WHERE earth_box(ll_to_earth($1,$2), $3) @&gt; ll_to_earth(lat, lng)
  ORDER by distance_metres;
  </code></pre>
  
  <p>And in my node server, I want to be able to be notified every time the number of rows in this query changes. I have looked into using a Node library such as <a href="https://github.com/nothingisdead/pg-live-query" rel="noreferrer">pg-live-query</a> but I would much rather pg-pubsub that works with existing Postgres LISTEN/NOTIFY in order to avoid unnecessary overhead. However, as far as I am able to understand, PostgreSQL <code>TRIGGERs</code> only work on UPDATE/INSERT/DELETE operations and not on any specific queries themselves. Is there any way to accomplish what I'm doing?</p>