Hi, I wonder if someone can help with this problem.
I need to set up a SELECT rule on a PostgreSQL View so that when a SELECT query is run, it doesn't get directly executed. Instead, a function gets run instead. The problem is, this function needs to know the content of the WHERE clause in the original query. Any idea how I can get hold of this in a SELECT rule?
I know that in the other rule types the NEW / OLD syntax can be used, but this doesn't work in SELECT.
To explain further:
The rule I've created is:
Code:
CREATE OR REPLACE RULE ccheslct AS
ON SELECT TO cache_data
DO INSTEAD
SELECT checkcache (trlvlid);
where the view is cache_data.
A query will be run on this in the format SELECT cche FROM cache_data WHERE trlvlid = (a number).
Is there any way I can get the value of the trlvlid passed in to the WHERE clause into the call to the checkcache () function?
I know that I could do this by just calling the function directly from the client application. However, I'm trying to keep changes to the (already existing) system as localised as possible.