0
0
PostgreSQLquery~10 mins

Why date handling matters in PostgreSQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the current date in PostgreSQL.

PostgreSQL
SELECT [1];
Drag options to blanks, or click blank then click option'
ACURRENT_DATE
BSYSDATE
CGETDATE()
DNOW()
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOW() returns date and time, not just the date.
GETDATE() and SYSDATE are not PostgreSQL functions.
2fill in blank
medium

Complete the code to extract the year from a date column named 'order_date'.

PostgreSQL
SELECT EXTRACT([1] FROM order_date) AS year FROM orders;
Drag options to blanks, or click blank then click option'
Amonth
Byear
Cday
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'month' or 'day' extracts wrong parts of the date.
Using 'hour' extracts time, not date.
3fill in blank
hard

Fix the error in the code to add 7 days to the current date.

PostgreSQL
SELECT CURRENT_DATE + [1];
Drag options to blanks, or click blank then click option'
A'7 days'
B7
CINTERVAL '7 days'
DDATE '7'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a plain number to a date causes an error.
Using a string without INTERVAL keyword is invalid.
4fill in blank
hard

Fill both blanks to convert a text '2024-06-15' to a date and then extract the month.

PostgreSQL
SELECT EXTRACT([1] FROM [2]('2024-06-15')) AS month;
Drag options to blanks, or click blank then click option'
Amonth
Byear
Cday
D::date
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'year' or 'day' instead of 'month' in EXTRACT.
Not casting the text to date before extracting.
5fill in blank
hard

Fill all three blanks to calculate the difference in days between two dates '2024-06-20' and '2024-06-15'.

PostgreSQL
SELECT ([1]('2024-06-20') - [2]('2024-06-15')) [3] '1 day' AS days_diff;
Drag options to blanks, or click blank then click option'
ADATE
C::interval
D::date
Attempts:
3 left
💡 Hint
Common Mistakes
Not casting strings to dates before subtraction.
Using interval cast incorrectly.