I am looking for an extension or a technique that will allow me to intercept a query by the exact query text, and replace that query with a different one.
What is sending the query?
In other words what library is the app using to communicate with the Postgres server?
I believe it is some ancient version of Hibernate.