简体   繁体   中英

Automatically call function after materialized view refresh?

Most question I've seen regarding materialized views and automation concerned either refreshing views periodically or refreshing them on some trigger.

It could be said, that my problem is reverse of that. Given some materialized view, I'd like to call some function that inserts some rows into some other table. So, basically something like "create trigger after refresh on ". The problem is, there's no such trigger type as "after refresh".

Is it achievable natively in Postgres?

The only way to do that is with an event trigger that fires ON ddl_command_end .

Check for TG_TAG = 'REFRESH MATERIALIZED VIEW' in the function body. Check the objid in the result of pg_event_trigger_ddl_commands() to know which materialized view was refreshed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM