Buncha
Buncha

Reputation: 51

PostgreSQL: Use current table in rule definition

Sometimes I need to copy/rename tables. My client is doing that work just fine, with one exception: new table's rules still contain references to old table.

Is there any way to not editing such rules? I'd prefer some keyword instead the table name, referencing to table, which the rule is triggered on...

Upvotes: 0

Views: 155

Answers (1)

Chris Travers
Chris Travers

Reputation: 26464

there is no easy way to do this with RULEs, but triggers provide this functionality, and in fact you can re-use trigger functions across tables.

This is one area where you will find triggers to be much more useful than rules.

Within a trigger, you can use TG_RELNAME for the current table name. Unfortunately such is not available within the RULEsystem however.

Upvotes: 1

Related Questions