postgresqldb2

DB2 to Postgres Migration: CURRENT_TIMESTAMP


I'm trying to rewrite IBM DB2 Queries to PostgreSQL.

According to DB2 UDB TO POSTGRESQL CONVERSION GUIDE the DB2 function CURRENT_TIMESTAMP can be migrated to the Postgres function CURRENT_TIMESTAMP. I don't think it's that simple.

According to this question and the documentation

PostgreSQL provides a number of functions that return values related to the current date and time. These SQL-standard functions all return values based on the start time of the current transaction

In other words, if there are multiple insert or update statements in a transaction that set the value of an attribute to CURRENT_TIMESTAMP, this timestamp will be the exact same for all rows. This behavior is different from DB2: DB2 uses the actual timestamp in each statement.

So I came across the Postgres functions clock_timestamp() and statement_timestamp().

I think the function statement_timestamp() is the right function to replace CURRENT_TIMESTAMP in DB2. However, I can not find any documentation that would confirm my assumption. I want to be sure that there are no side-effects when replacing all CURRENT_TIMESTAMP with statement_timestamp() - can someone confirm this?


Solution

  • I replaced CURRENT_TIMESTAMP in DB2 with statement_timestamp() in PostgreSQL, and so far, we have not experienced any side effects. The documentation is already linked in the question. I will mark this as the answer unless someone proves otherwise.