Challenge - 5 Problems
Integer Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of integer type casting in PostgreSQL
What is the output of this query in PostgreSQL?
SELECT 32767::smallint + 1::smallint AS result;PostgreSQL
SELECT 32767::smallint + 1::smallint AS result;
Attempts:
2 left
💡 Hint
Remember the range of smallint is from -32768 to 32767.
✗ Incorrect
Adding 1 to the maximum smallint value causes an overflow error in PostgreSQL; it does not wrap around.
❓ query_result
intermediate2:00remaining
Result of integer multiplication exceeding integer range
What is the output of this query?
Assuming default integer type in PostgreSQL.
SELECT 50000 * 50000 AS result;Assuming default integer type in PostgreSQL.
PostgreSQL
SELECT 50000 * 50000 AS result;
Attempts:
2 left
💡 Hint
Default integer is 4 bytes with range -2147483648 to 2147483647.
✗ Incorrect
The multiplication result exceeds the 4-byte integer range and causes an overflow error in PostgreSQL.
📝 Syntax
advanced2:00remaining
Identify the correct syntax for declaring a bigint column
Which of the following SQL statements correctly creates a table with a bigint column named 'id' in PostgreSQL?
Attempts:
2 left
💡 Hint
Check the exact spelling of the bigint type.
✗ Incorrect
The correct PostgreSQL type is BIGINT. Other options have spelling or spacing errors causing syntax errors.
❓ optimization
advanced2:00remaining
Choosing the best integer type for storing ages
You want to store ages of people in a PostgreSQL table. Ages range from 0 to 120. Which integer type is the most efficient choice?
Attempts:
2 left
💡 Hint
Consider the range and storage size of each type.
✗ Incorrect
smallint uses 2 bytes and can store values from -32768 to 32767, which covers 0 to 120 efficiently.
🧠 Conceptual
expert2:00remaining
Understanding integer overflow behavior in PostgreSQL
What happens when you insert a value larger than 2147483647 into an integer column in PostgreSQL without explicit type casting?
Attempts:
2 left
💡 Hint
Think about how PostgreSQL handles out-of-range values for integer columns.
✗ Incorrect
PostgreSQL raises an error when a value exceeds the integer range; it does not truncate, wrap, or auto-convert types.