cancel
Showing results for 
Search instead for 
Did you mean: 

How to use REFRESH MATERIALIZED VIEW in trigger?

03-22-2012 10:21 AM
MCMartin Participant
8601 views 8 comments Go to solution
SAP Managed Tags
Subscribe

For a materialized view which is in manual refresh mode, what is the best approach to use REFRESH MATERIALIZED VIEW from inside a trigger.

REFRESH MATERIALIZED VIEW will commit the data, which for me broke the overall logic.

So how to overcome this limitation and still refresh the view triggered by a trigger.

Immediate refresh mode is not possible to use, because my materialized view has no unique index column.

Accepted Solutions (1)

Accepted Solutions (1)

Breck_Carter
Participant

Put the refresh in an EVENT and use TRIGGER EVENT in the trigger.

VolkerBarth
Contributor
0 Likes

...and make sure the event closes immediately if it is not the only instance running...

MCMartin
Participant
0 Likes

I was to quick, in accepting the answer, Trigger Event needs DBA authority, how to do this when the executing user is not DBA?

Breck_Carter
Participant

Put the TRIGGER EVENT inside a procedure owned by DBA, and GRANT EXECUTE on that procedure... procedures run with the permissions of the owner rather than the caller.

Breck_Carter
Participant
0 Likes

Why bother? If you were running the REFRESH in some other non-EVENT context, would you bother checking to see if a REFRESH was already running? ...that's what locks and blocks are for 🙂

MCMartin
Participant
0 Likes

thanks that works

VolkerBarth
Contributor
0 Likes

I would bother when it is used inside a trigger (as it is the case here), as I would assume

  • that DML statements might be executed very frequently, and
  • that the REFRESH is an expensive operation.

Additionally, I do assume that the trigger is a statement-level one, otherwise it could be called several times for one DML statement.


If this is a rarely modified table, well, then my point is surely moot.

VolkerBarth
Contributor
0 Likes

...at least that's the DEFAULT - cf. this other FAQ on the SQL SECURITY INVOKER clause...

(which I have never used in production code...)

Answers (0)