Sample Exam Questions

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

Sample Question

3.34

Choose two correct data types that can be used for tables in PostgreSQL.


  1. The 'integer' type is a 4-byte integer.

  2. The 'unsigned int' type can be used to handle non-negative integers.

  3. The 'long int' type can be used to handle 8-byte integers.

  4. The 'byte' type can be used to handle one-byte integers.

  5. The 'numeric' type can handle decimal numbers with more than 40 digits, including the decimal point.

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

Answer and Explanation

For integers, PostgreSQL supports the 2-byte 'smallint' type (ranging from -32768 to +32767), the 4-byte 'integer' type (ranging from -2147483648 to +2147483647), and the 8-byte 'bigint' type (ranging from -9223372036854775808 to +9223372036854775807). In many environments, the 'integer' type will be sufficient. However, if you are under strict disk space constraints and only use relatively small integers, you might use the 'smallint' type. If there is a possibility of using large integers exceeding 2 billion, you would use the 'bigint' type. You can also write 'int' as a substitute for 'integer'. Although 'int8' is supported as a notation for 'bigint', 'long int' is not allowed.

While some types of databases support 1-byte integers or non-negative (unsigned) integers, PostgreSQL does not.

PostgreSQL supports the 'real' type (single precision) and the 'double precision' type for handling floating-point numbers. However, these types can cause errors when dealing with decimal numbers, such as when multiplying 0.1 by 10 does not result in 1. To perform decimal operations without such errors (which is important for calculations involving money), the 'numeric' type is supported. With the 'numeric' type, you define the data type by specifying the maximum number of digits and the number of digits after the decimal point, up to a maximum of 1000 digits (which can essentially be considered unlimited). You can also write 'decimal' as a substitute for 'numeric'.

Therefore, the correct answers are A and E.

For more information on the numeric data types available in PostgreSQL, please refer to https://www.postgresql.org/docs/14/datatype-numeric.html