What is the range of values for the smallint type in PostgreSQL?
The smallint type stores integers from -32,768 to 32,767.
Click to reveal answer
beginner
Which integer type in PostgreSQL can store the largest whole numbers?
The bigint type can store the largest whole numbers, ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Click to reveal answer
beginner
What is the default integer type in PostgreSQL when you use integer?
The integer type (also called int) stores whole numbers from -2,147,483,648 to 2,147,483,647.
Click to reveal answer
intermediate
Why would you choose smallint over integer or bigint?
You choose smallint to save storage space when you know your numbers will fit in its smaller range, like counting items that never exceed 32,767.
Click to reveal answer
intermediate
What happens if you try to store a number outside the range of an integer type in PostgreSQL?
PostgreSQL will give an error because the number is too big or too small for that type. You need to use a larger integer type or handle the value differently.
Click to reveal answer
Which PostgreSQL integer type uses 8 bytes of storage?
What is the maximum positive value for the integer type?
A2,147,483,647
B32,767
C9,223,372,036,854,775,807
D4,294,967,295
✗ Incorrect
integer stores values up to 2,147,483,647.
If you need to store a number larger than 2 billion, which type should you use?
Asmallint
Binteger
Ctext
Dbigint
✗ Incorrect
bigint can store numbers larger than 2 billion.
How many bytes does the smallint type use?
A2 bytes
B1 byte
C4 bytes
D8 bytes
✗ Incorrect
smallint uses 2 bytes of storage.
What will happen if you insert the number 100,000 into a smallint column?
AIt will store the number correctly.
BIt will cause an error due to overflow.
CIt will round the number down.
DIt will convert the number to text.
✗ Incorrect
100,000 is outside the smallint range, causing an overflow error.
Explain the differences between smallint, integer, and bigint in PostgreSQL.
Think about how much space each type uses and the size of numbers they can hold.
You got /3 concepts.
Describe what happens if you try to store a number too large for the chosen integer type in PostgreSQL.
Consider what PostgreSQL does when data doesn't fit the type.
You got /3 concepts.
Practice
(1/5)
1. Which PostgreSQL integer type is best suited for storing very large whole numbers?
easy
A. bigint
B. smallint
C. integer
D. decimal
Solution
Step 1: Understand integer types and their sizes
smallint stores small numbers, integer stores medium-sized numbers, and bigint stores very large numbers.
Step 2: Identify the type for very large whole numbers
Since the question asks for very large whole numbers, bigint is the correct choice.
Final Answer:
bigint -> Option A
Quick Check:
Very large whole numbers = bigint [OK]
Hint: Biggest integer type is bigint for very large numbers [OK]
Common Mistakes:
Confusing smallint with bigint
Choosing decimal which is for decimals, not integers
Picking integer which is medium size
2. Which of the following is the correct way to declare a column named age as a 2-byte integer in PostgreSQL?
easy
A. age INT2(2);
B. age INTEGER(2);
C. age BIGINT(2);
D. age SMALLINT;
Solution
Step 1: Recall PostgreSQL integer type syntax
PostgreSQL uses SMALLINT for 2-byte integers. The syntax is simply column_name SMALLINT;.
Step 2: Evaluate each option
age SMALLINT; uses correct syntax. The other options incorrectly use size in parentheses (like INT2(2), INTEGER(2), BIGINT(2)), which is invalid for integer types in PostgreSQL.
Final Answer:
age SMALLINT; -> Option D
Quick Check:
2-byte integer = SMALLINT syntax [OK]
Hint: Use SMALLINT keyword for 2-byte integers, no size in parentheses [OK]
Common Mistakes:
Adding size in parentheses like INTEGER(2)
Using BIGINT for small numbers
Specifying size like INT2(2) for integer types
3. What will be the result of this PostgreSQL query?
CREATE TABLE test_numbers (num SMALLINT); INSERT INTO test_numbers VALUES (40000); SELECT * FROM test_numbers;
medium
A. 40000
B. Error: integer out of range
C. 0
D. NULL
Solution
Step 1: Understand SMALLINT range
SMALLINT can store values from -32768 to 32767 only.
Step 2: Check inserted value against range
40000 is greater than 32767, so inserting it causes an error.
Final Answer:
Error: integer out of range -> Option B
Quick Check:
40000 > SMALLINT max 32767 = error [OK]
Hint: Check value fits type range; else error occurs [OK]
Common Mistakes:
Assuming value truncates silently
Expecting 0 or NULL instead of error
Confusing SMALLINT range with INTEGER
4. You wrote this table definition:
CREATE TABLE sales (id INTEGER, amount SMALLINT);
But when inserting a large amount like 40000, you get an error. How do you fix it?
medium
A. Change amount column type to INTEGER
B. Change id column type to SMALLINT
C. Insert smaller values only
D. Change amount column type to tinyint
Solution
Step 1: Identify cause of error
Amount column is SMALLINT which maxes at 32767, so 40000 is too large.
Step 2: Choose appropriate type to hold 40000
INTEGER can hold values up to 2,147,483,647, so changing amount to INTEGER fixes the error.
Final Answer:
Change amount column type to INTEGER -> Option A
Quick Check:
40000 fits INTEGER but not SMALLINT [OK]
Hint: Use INTEGER for values larger than 32767 [OK]
Common Mistakes:
Changing unrelated column type
Trying to insert smaller values only
Choosing tinyint which is a MySQL type, not PostgreSQL
5. You need to store user IDs that can be very large numbers, possibly exceeding 2 billion. Which PostgreSQL integer type should you choose and why?
hard
A. smallint because it uses less storage
B. integer because it supports up to 2 billion
C. bigint because it supports numbers larger than 2 billion
D. serial because it auto-increments
Solution
Step 1: Understand size limits of integer types
smallint max is 32767, integer max is about 2,147,483,647, bigint supports much larger numbers.
Step 2: Match requirement to type
User IDs may exceed 2 billion, so integer is insufficient. bigint is needed to store larger values.
Final Answer:
bigint because it supports numbers larger than 2 billion -> Option C
Quick Check:
IDs > 2 billion need bigint [OK]
Hint: Use bigint for numbers larger than 2 billion [OK]
Common Mistakes:
Choosing smallint for large IDs
Assuming integer supports >2 billion
Confusing serial with integer size
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.