Ok.
The setting is meant to avoid reading a new sequence value for a sequenced PK field. So what the trigger does is not important, all the setting does is use the existing sequence value instead of a new one.
This setting is required, as the value created by the trigger has to be returned, and the engine doesn't know that it should do that if the field isn't marked as a field which is sequenced.
So to recap, the problem comes down to: the value passed as the value for the sequenced field in the insert query can make triggers not produce the proper value in some cases. I agree that passing GEN_ID(sequence, 0) is indeed perhaps a bit odd, as the value produced by it isn't the right one anyway (as it's the value the sequence is on currently).
The order is (correct me if I'm wrong, please):
- INSERT statement is formulated, fields get the value to insert
- BEFORE INSERT trigger is executed, it can overwrite the values set to insert
- Row is actually inserted into table.
- AFTER INSERT trigger runs.
- Output parameters are returned.
So a BEFORE INSERT trigger will overwrite the value in normal occasions, with the new value for a given sequence. In the current situation, the value for the field the trigger sees is always > 0 and is basically the sequence's current value.
I can't see how things will fail if I pass NULL indeed: the sequenced field is expected to get a new value in the trigger (otherwise the setting should be off). AFTER insert triggers will only work if there's a valid row inserted, and will never overwrite the value with a new sequence value, as the row has already been inserted (and this is only possible with a valid value)
I'll make the change to pass NULL instead of GEN_ID(sequence, 0), as it makes triggers work which will now fail, but won't make currently working triggers fail, as they overwrite the value currently already.