Michigan Man
Michigan Man

Reputation: 101

postgreSQL create rule on select where clause

I would like some assistance on the syntax on creating a rule that includes a where clause.

Here is what I have so far

CREATE RULE CodeRetrieve AS  
    ON SELECT TO RC.Code from RC WHERE RC.CODEID = FromQuery.CODEID
    DO INSTEAD  
    RCAA.Code from RCAA WHERE RCAA.CODEID = FromQuery.CODEID   

Basically, by default I want to redirect the query from one table to another and return the results from the RCAA table.

Reason? To avoid going thru the code in a gazillion places and changing the query. Just wanted to experiment with changing the code in one place, i.e. a database rule.

Thanks.

Upvotes: 0

Views: 1170

Answers (1)

dante vitale
dante vitale

Reputation: 36

To redirec query from old table to new table maybe you don't need a rule but only some DDL and plane old sql. If you rename your table RC (for example in "_RC") and create view RC as select * from RCAA (eventually with a "where" filter) your gazillion lines of code need no change for the select query. in case of need of action query you can add a rule on the RC view.

Upvotes: 1

Related Questions