0
0
PostgreSQLquery~20 mins

Integer types (smallint, integer, bigint) in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Integer Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
A32768
BNULL
C-32768
DOverflow error
Attempts:
2 left
💡 Hint
Remember the range of smallint is from -32768 to 32767.
query_result
intermediate
2:00remaining
Result of integer multiplication exceeding integer range
What is the output of this query?

SELECT 50000 * 50000 AS result;

Assuming default integer type in PostgreSQL.
PostgreSQL
SELECT 50000 * 50000 AS result;
ANULL
BOverflow error
C2500000000
D-1794967296
Attempts:
2 left
💡 Hint
Default integer is 4 bytes with range -2147483648 to 2147483647.
📝 Syntax
advanced
2: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?
ACREATE TABLE users (id BIG INT);
BCREATE TABLE users (id BIGINTEGER);
CCREATE TABLE users (id BIGINT);
DCREATE TABLE users (id BIGINTGER);
Attempts:
2 left
💡 Hint
Check the exact spelling of the bigint type.
optimization
advanced
2: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?
Asmallint
Binteger
Cbigint
Dnumeric
Attempts:
2 left
💡 Hint
Consider the range and storage size of each type.
🧠 Conceptual
expert
2: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?
APostgreSQL raises an error and rejects the insert.
BThe value is truncated to 2147483647 without error.
CThe value wraps around to a negative number silently.
DPostgreSQL automatically converts the column to bigint.
Attempts:
2 left
💡 Hint
Think about how PostgreSQL handles out-of-range values for integer columns.