on 2020 Feb 17 7:47 AM
Hi, I need to execute an automatic commited statement (alter event statement) within a trigger of a table.
I get an error message stating: COMMIT/ROLLBACK not allowed within atomic operation! Error Code = -267, SQL State = 42000.
Is there any workaround to get this working?
Request clarification before answering.
A trigger runs as atomic part of the triggering DML statement (i.e. the according INSERT/UPDATE/DELETE/MERGE statement) and as such cannot do a commit on its own, it must be part of the trancsaction the according statement belongs to. (Aside: Within a trigger you can use the ROLLBACK TRIGGER statement, and that will also rollback the according statement.)
However, you could start an event from within your trigger, and events run in their own connections and therefore in their own transactions. There are several discussions in this forum dealting with such setups.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, as an ALTER EVENT like most (or all?) DDL statement issues an automatic commit, you cannot run that from your trigger code - but you could trigger another event that itself calls ALTER EVENT.
You could even use the EVENT_PARAMETER function to supply the according information from the trigger to the event.
See a sample there for the latter.
Well, you could use the parameter to specify the start time (or whatever has to be changed), unless that information is available other wise. You could also use several parameters to specify both the event name and the start time or whatever, so your "helper event" could alter different events...
It's just a way to "transport information" between the invoker of the event (here your trigger) and the event itself. Of course you could also use database-scope variables (in v17) or (possibly temporary share by all) tables to do so.
Triggers execute using the privileges of the owner of the table on which they are defined, not the privileges of the user who caused the trigger to fire, and not the privileges of the user who created the trigger.
If the table owner is not the one who created the event, I guess you need to
Only if I knew how to insert photos in this page!! https://www.quora.com/What-does-the-term-hats-off-mean
Respect and Thanks!!!!
Here is how to insert an image into a comment: Use naked HTML like this...
<img src="https://qph.fs.quoracdn.net/main-qimg-94e93244063f7294636ee10532cc5896.webp" width="200">
You're limited to using links to images; you cannot upload images to this forum any more.
Also, the width="xxx" attribute is very handy to make giant images fit into comments.
Another tip: If you are trying to show HTML in a PRE tab (like above), change all embedded "<" characters to "<"
User | Count |
---|---|
64 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.