Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.2 Functions and operators (Date/Time functions)

Sample Question


"Select statement for a function that returns the current time, current_timestamp, was executed twice in succession as follows:

select current_timestamp;
select current_timestamp;

Both times, the same value was returned. Choose the most appropriate reason for this."

  1. The server machine's hardware clock is faulty.
  2. The timed command is not executed on the server machine, so the time is not accurately maintained.
  3. The same time was returned because the two SELECT statements were executed quickly in succession, without any gap.
  4. The BEGIN command was executed just before these SELECT statements.
  5. When executed from the same session, current_timestamp always returns the same value.

※This sample exam is different from those that appear in the actual OSS-DB Exam.

Answer and Explanation

current_timestamp (it is a "function" but used without parentheses) returns the current time in microseconds. However, within a transaction, it returns the start time of the transaction, meaning it always returns the same value within the same transaction. Since it is in microseconds, even if you execute it quickly in succession, it will not return the same value. Also, even within the same session, if the transactions are different, it will return different values. In option D, by executing the BEGIN command just before the two subsequent SELECT statements, they are executed within the same transaction.

Therefore, the correct answer is D.

In the PostgreSQL extension, there is a function called transaction_timestamp(), which, as the name suggests, returns the start time of the transaction. However, current_timestamp also has the same meaning.
Also, as part of the PostgreSQL extension, for cases where you want to get the time when each SQL was actually executed within a transaction, functions like statement_timestamp() and clock_timestamp() are available. They return the time when the SQL statement was executed and the time when the function was actually executed within the SQL, respectively.