In PostgreSQL, if you want to set current timestamp as default value, you can simply keep a column’s default expression as now()
. However, by default there is no function defined to update the timestamp when a particular row (or multiple rows) need to be updated.
In such scenario, you may create your custom method and trigger it using PostgreSQL’s Triggers. Following snippet will make it more clear:
Here, we are creating a new method, method_get_updated_at()
Once it is created, use the following snippet to trigger it:
If you want to delete a Trigger, you can use this simple query:
Note: Please update the
ALso, if you want to view all existing methods, run this query:
And, run this query to view all Triggers:
Thanks!