0
0
PostgreSQLquery~20 mins

TO_DATE and TO_TIMESTAMP for parsing in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
TO_DATE and TO_TIMESTAMP Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What is the output of this TO_DATE query?
Given the query:
SELECT TO_DATE('2024-06-15', 'YYYY-MM-DD');

What is the output?
PostgreSQL
SELECT TO_DATE('2024-06-15', 'YYYY-MM-DD');
AError: invalid input syntax for type date
B2024-06-15 00:00:00
C2024-06-15
DNULL
Attempts:
2 left
💡 Hint
TO_DATE returns a date type without time part.
query_result
intermediate
1:30remaining
What does this TO_TIMESTAMP query return?
Consider this query:
SELECT TO_TIMESTAMP('2024-06-15 14:30:45', 'YYYY-MM-DD HH24:MI:SS');

What is the output?
PostgreSQL
SELECT TO_TIMESTAMP('2024-06-15 14:30:45', 'YYYY-MM-DD HH24:MI:SS');
A2024-06-15 14:30:45
BError: invalid input syntax for type timestamp
C2024-06-15 00:00:00
D2024-06-15 14:30:45+00
Attempts:
2 left
💡 Hint
TO_TIMESTAMP returns a timestamp without time zone.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in TO_DATE usage?
Identify which query will cause a syntax error:
ASELECT TO_DATE('15-06-2024', 'DD-MM-YYYY');
BSELECT TO_DATE('2024/06/15', 'YYYY/MM/DD');
CSELECT TO_DATE('2024-15-06', 'YYYY-DD-MM');
DSELECT TO_DATE('2024-06-15', 'YYYY-DD-MM');
Attempts:
2 left
💡 Hint
Check if the format matches the input string exactly.
query_result
advanced
2:00remaining
What is the output of this TO_TIMESTAMP with fractional seconds?
Given:
SELECT TO_TIMESTAMP('2024-06-15 14:30:45.123456', 'YYYY-MM-DD HH24:MI:SS.US');

What is the output?
PostgreSQL
SELECT TO_TIMESTAMP('2024-06-15 14:30:45.123456', 'YYYY-MM-DD HH24:MI:SS.US');
A2024-06-15 14:30:45.123456
B2024-06-15 14:30:45
C2024-06-15 14:30:45.123
DError: invalid input syntax for type timestamp
Attempts:
2 left
💡 Hint
US means microseconds in the format string.
🧠 Conceptual
expert
2:30remaining
Why does TO_DATE discard time information while TO_TIMESTAMP preserves it?
Choose the best explanation:
ATO_DATE always converts input to midnight time; TO_TIMESTAMP converts input to noon time.
BTO_DATE returns a date type which stores only year, month, and day; TO_TIMESTAMP returns a timestamp type that stores date and time.
CTO_DATE converts strings to text format; TO_TIMESTAMP converts strings to binary format.
DTO_DATE and TO_TIMESTAMP both preserve time, but TO_DATE hides it by default.
Attempts:
2 left
💡 Hint
Think about the data types returned by each function.