PostgreSQL: Update the Timestamp column with the use of TRIGGER

Like MySQL, PostgreSQL doesn’t have different column for Datetime and Timestamp.
You can visit this MySQL article here:

In this post, I am sharing small demonstration to automatically update a timestamp column when a row is updated in the table of the PostgreSQL.

In the big transactional system like banking system, we always require to know last updated datetime of each and every transaction and rows.

We have also common practice to create last_modified_datetime column in table.
We can also update this column using application and we can also update this column using user defined function.
But we can also create Trigger to perform this operation and this automatic approach is good.

Below is a small demonstration by creating update Trigger:

Create a sample table:

Insert a sample data for EmpName and EmpDOB column:

Create a Trigger function:


Update one record and check LastUpdatedDateTime:

The Result:

PostgreSQL Update TimeStamp

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of