Hint: Use commas inside parentheses for parameters [OK]
Common Mistakes:
Using keywords like TO or STEP inside function
Missing commas between parameters
Adding extra keywords inside parentheses
Using FROM or BY keywords incorrectly
3. What is the output of this query?
SELECT * FROM GENERATE_SERIES(3, 9, 3);
medium
A. [3, 9]
B. [3, 4, 5, 6, 7, 8, 9]
C. [3, 6, 9]
D. Empty result
Solution
Step 1: Identify start, stop, and step values
Start=3, stop=9, step=3 means numbers increase by 3 from 3 up to 9.
Step 2: List generated numbers
Numbers are 3, then 6 (3+3), then 9 (6+3). It stops at 9.
Final Answer:
[3, 6, 9] -> Option C
Quick Check:
Step 3 increments from 3 to 9 = [3,6,9] [OK]
Hint: Step controls increments; count from start to stop by step [OK]
Common Mistakes:
Listing all numbers between start and stop ignoring step
Only showing start and stop values
Expecting empty result if step is not 1
Confusing step as a filter
4. Why does this query produce no results?
SELECT * FROM GENERATE_SERIES(5, 1, 1);
medium
A. No error; it returns numbers 5 to 1
B. Step cannot be 1
C. Syntax error due to missing commas
D. No results because start is greater than stop with positive step
Solution
Step 1: Analyze start, stop, and step values
Start=5, stop=1, step=1 means counting up from 5 to 1 by 1, which produces no rows.
Step 2: Understand GENERATE_SERIES behavior
With positive step, start must be less than or equal to stop; otherwise, no rows are generated.
Final Answer:
No results because start is greater than stop with positive step -> Option D
Quick Check:
Positive step requires start ≤ stop [OK]
Hint: Step sign must match direction from start to stop [OK]
Common Mistakes:
Assuming it counts down with positive step
Ignoring step sign rules
Thinking syntax error occurs here
Expecting reversed sequence automatically
5. You want to generate a sequence of dates from January 1, 2024 to January 10, 2024, stepping by 2 days. Which query correctly does this?
hard
A. SELECT * FROM GENERATE_SERIES('2024-01-01'::date, '2024-01-10'::date, '2 days'::interval);
B. SELECT * FROM GENERATE_SERIES('2024-01-01', '2024-01-10', 2);
C. SELECT * FROM GENERATE_SERIES('2024-01-01'::date, '2024-01-10'::date, 2);
D. SELECT * FROM GENERATE_SERIES('2024-01-01'::timestamp, '2024-01-10'::timestamp, '2');
Solution
Step 1: Understand date sequence generation
To generate dates, start and stop must be dates, and step must be an interval like '2 days'.
Step 2: Check each option's correctness
SELECT * FROM GENERATE_SERIES('2024-01-01'::date, '2024-01-10'::date, '2 days'::interval); uses dates cast properly and interval '2 days' as step, which is correct.
Final Answer:
SELECT * FROM GENERATE_SERIES('2024-01-01'::date, '2024-01-10'::date, '2 days'::interval); -> Option A
Quick Check:
Date range with interval step requires casting and interval [OK]
Hint: Use date::date and step as interval like '2 days' [OK]
Common Mistakes:
Using integer step for dates
Not casting strings to date or interval
Using plain numbers as step with dates
Casting step incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.