Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.1 SQL commands (SELECT statement)

Sample Question

3.28

When you use psql and run 'select current_timestamp;' to check the current time, the result is:

      current_timestamp
-------------------------------
2021-02-26 22:31:02.311235+09
(1 line)

However, when you run 'select current_timestamp from x;', the result is:

current_timestamp
-------------------
(0 lines)

Choose the most appropriate reason why the current time is not displayed when 'from x' is specified.
 


  1. Table x does not exist.

  2. You do not have SELECT privilege on table x.

  3. Table x does not have a current_timestamp column.

  4. Table x exists but contains no rows of data.

  5. You should not specify a from clause when retrieving current_timestamp.

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

Answer and Explanation

The basic form of the SELECT statement is often taught as:

SELECT column_list FROM table_name WHERE condition_expression

The operation of this statement is to retrieve rows from the table specified in the FROM clause that match the condition expression specified in the WHERE clause (or all rows if the WHERE clause is omitted). Then, for each retrieved row, it outputs the result of executing the calculation specified in the column_list. The calculation specified in the column_list does not necessarily have to include columns defined in the table. It can be a function like current_timestamp. Therefore, the SELECT statement can be used not only for searching data in a table but also for simple calculations like executing a function.

In PostgreSQL, the FROM clause can be omitted. So, you can simply execute "select expression" to get the result of the calculation. However, some types of databases do not allow the FROM clause to be omitted. In such cases, a dummy table containing only one row of data is specified in the FROM clause.

It's important to note that the calculation result is output for each retrieved row. Therefore, if there is only one row of data in the table, there will be only one output. However, if there are 100 rows of data, the same result will be output 100 times. Conversely, if there is no data, the result will be zero rows.

In other words, if there is no data in table x, a phenomenon like the one in the example will occur. If table x does not exist or if you do not have SELECT privilege, you will not be able to retrieve the current time. However, in this case, you will get an error stating that x does not exist or that you do not have the privilege, which is a different result from the example.

Therefore, the correct answer is D.