0

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?

1
  • Interesting use case! I'm not aware of such triggers. Would a trigger on the origin table(s) to call this function be an option? Commented Dec 18, 2020 at 13:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.