Sample Exam Questions

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

Sample Question

3.21

Choose three correct descriptions of PostgreSQL functions.


  1. Use the rounddown function to truncate a decimal part to an integer.

  2. Use the trunc function to truncate the decimal part to an integer.

  3. Use the roundup function to round up a decimal part to an integer.

  4. Use the ceil function to round up a decimal part to an integer.

  5. Use the round function to round the decimal part to an integer.

  6. Use the int function to round a decimal part to an integer.

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

Answer and Explanation

Calculations such as truncating, rounding up, and rounding decimals to integers, or processing to a certain number of decimal places, are commonly used. However, be careful not to get confused as different tools and systems may use different functions or have slightly different behaviors.

In PostgreSQL, to truncate a number like 12.345 to 12, you use the 'trunc' function.
To round up a number like 12.345 to 13, you use the 'ceil' or 'ceiling' function.
To round a number like 12.345 to 12 or 34.567 to 35, you use the 'round' function.

Therefore, the correct answers are B, D, and E.

You can verify these behaviors by executing queries like 'select trunc(12.345), ceil(12.345), round(12.345), round(34.567);', so it's a good idea to try them out.

For 'trunc' and 'round', you can specify the number of decimal places as a second argument. For example, if you execute 'select trunc(12.345, 2), round(12.345, 2);', it will return 12.34 and 12.35.
You can also specify a negative number for this argument. Try executing 'round(12.345, -1)' to see what value it returns.

Also, people may have different interpretations of how to truncate or round up negative values. You can check how PostgreSQL handles this by executing 'select trunc(-12.345), ceil(-12.345);'.