my updated_at
column is set to current timestame ON UPDATE
.
If the column active
was False and is changed to True, I also want to change activated_at
to be the same value as updated_at
.
will the query
UPDATE mytable
SET active=TRUE, activated_at=mytable.updated_at
WHERE active=FALSE;
use the new post-on update
value of updated_at
, or the old one, or is the behavior undefined?
2
Answers
Your Query is incorrect. You need a
select
query to get theupdated_at
value:I suppose a simple test will probably get the answer faster for you than asking.
Let’s try your query:
As demonstrated above, the updated rows are using the OLD values before the timestamp auto-update kicks in. To circumvent that, we can simply set the value to the current datetime:
Here is the slightly modified query:
That’s it.