SQLite Forum

How to write this trigger?
Login
Hello, Eponymous,

It works for the `INSERT` trigger.  Thank you.

Unless I turn off recursive_triggers with `pragma recursive_triggers=on/off;` at the global level, it fails on `UPDATE` trigger (same code) with `Error: too many levels of trigger recursion`.

`pragma recursive_triggers=on/off;` is not valid inside triggers, which would let me turn it off before the `UPDATE` statement, and turn it back on afterwards.

For my specific example, how do I prevent recursion inside the `UPDATE` trigger?
Can I write the operation in a different way that does not cause recursion?
Or, is the only option to have recursive triggers turned off all the time?

---

Is `SELECT new.notes = replace...` allowed syntax (I mean the assignment part) for SQLite3? I couldn't find it [here](https://sqlite.org/lang_createtrigger.html) or [here](https://sqlite.org/lang_select.html).

My attempt did not work but it also did not produce any syntax errors.

---

I chose a `BEFORE` trigger because even though in my given example it wouldn't make a difference, in other cases where there is a `CHECK` constraint.  wouldn't an `AFTER` trigger be too late if the unaltered value happened to violate the constraint?  Or, will the constraint fire after the `AFTER` trigger?

For example, a phone number must be N-digits long including the country code.  The trigger makes sure to normalize the local number to the correct number of digits.  Will the `AFTER` trigger complete its job before the `CHECK` runs?