From 2023-01-01 to 2024-06-01 is 1 year and 5 months exactly.
Step 2: Understand AGE output format
AGE returns interval as years, months, and days; days are zero here.
Final Answer:
1 year 5 mons 0 days -> Option D
Quick Check:
AGE returns 1 year 5 mons 0 days [OK]
Hint: Count full years and months between dates [OK]
Common Mistakes:
Counting months incorrectly as 6 instead of 5
Confusing days count
Assuming AGE returns total days only
4. Identify the error in this query:
SELECT AGE('2023-01-01');
medium
A. Incorrect date format used
B. AGE function cannot accept a single argument
C. No error; AGE accepts a single argument
D. AGE requires casting to timestamp explicitly
Solution
Step 1: Check AGE function argument requirements
AGE can accept one or two arguments; with one argument it returns difference from current date.
Step 2: Analyze the query
The query uses one argument but does not cast it; however, AGE accepts one argument as timestamp or date.
Step 3: Identify actual error
The query is valid; PostgreSQL implicitly handles the date string and computes age to current timestamp. No error.
Final Answer:
No error; AGE accepts a single argument -> Option C
Quick Check:
AGE needs two timestamps or one with current date [OK]
Hint: AGE with one argument uses current date [OK]
Common Mistakes:
Assuming AGE always needs two arguments
Thinking date format is wrong
Believing casting is mandatory
5. You want to find the exact age difference between a person's birthdate '1990-04-15' and today, but only in years ignoring months and days. Which query correctly uses AGE and extracts only the years part?
hard
A. SELECT EXTRACT(YEAR FROM AGE(CURRENT_DATE, '1990-04-15'));
B. SELECT EXTRACT(YEAR FROM AGE('1990-04-15', CURRENT_DATE));
C. SELECT AGE(CURRENT_DATE, '1990-04-15')::year;
D. SELECT DATE_PART('year', AGE('1990-04-15', CURRENT_DATE));
Solution
Step 1: Use AGE with current date and birthdate
AGE(CURRENT_DATE, '1990-04-15') returns interval from birthdate to today.
Step 2: Extract only the year part
Use EXTRACT(YEAR FROM interval) to get full years ignoring months and days.
Final Answer:
SELECT EXTRACT(YEAR FROM AGE(CURRENT_DATE, '1990-04-15')); -> Option A
Quick Check:
EXTRACT YEAR from AGE with later date first [OK]
Hint: Use EXTRACT(YEAR FROM AGE(later, earlier)) [OK]
Common Mistakes:
Reversing AGE argument order
Using wrong function like DATE_PART with reversed arguments
Trying to cast interval directly to year
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.