I'm trying to create a trigger to update a value after insertion, or before it works.
I have the following table: test
Remembering that the date field type is timestamp
and the default value is CURRENT_TIMESTAMP
id | date | dado | dado2
1 | 2018-10-22 14:43:32 | Dado 1 |
2 | 2018-10-22 14:44:40 | Dado 2 |
3 | 2018-10-22 14:44:41 | Dado 3 |
4 | 2018-10-22 14:45:41 | Dado 4 |
If I do the trigger using before insert
, when using the field new.date
the value comes null.
CREATE TRIGGER 'teste_before_insert' BEFORE INSERT ON 'teste' FOR EACH ROW BEGIN
insert into debug_table (condicao, condicao2) VALUES (new.date, new.id);
END
This table debug_table was created to know if the value is coming, it inserts, but with null data
But if I use after insert
, the field is filled in. I just want to update the dado 2
field.
So since the value works with after insert
, I would like to update the same table with this trigger in the dado 2
But it seems that the update does not work