Brightlane's reporting dashboard stores events as timezone-aware timestamps but displays only the calendar date. The engineering team is verifying the chained cast that performs the conversion.
Write a query to return the string '2024-06-15 22:45:00+00' cast first as a timezone-aware timestamp, then to a timezone-naive timestamp, and finally to a calendar date.
Output:
- A single row with one column,
report_date, typed as a date.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
'2024-06-15 22:45:00+00'::TIMESTAMPTZ::TIMESTAMP::date AS report_date The shape
'2024-06-15 22:45:00+00'::timestamptz::timestamp::date runs three casts in left-to-right order, and each one drops a layer of information. The first lands the absolute moment, the second strips the zone, and the third strips the time-of-day. The final column is DATE, which is what the reporting dashboard displays.
Clause by clause
SELECT '2024-06-15 22:45:00+00'::timestamptz::timestamp::date AS report_dateevaluates the literal once and applies three casts. The first::timestamptzresolves the string as aTIMESTAMPTZ, taking the+00offset and storing2024-06-15 22:45:00in UTC. The second::timestampconverts thatTIMESTAMPTZback to a timezone-naiveTIMESTAMPusing the session zone for the conversion. The third::datedrops the time-of-day, leaving2024-06-15.- There is no
FROMbecause no table is being read.
Why each cast in the chain earns its place
The chained shape documents the contract of the reporting dashboard: data arrives as TIMESTAMPTZ, gets reduced to a naive TIMESTAMP for display in the local frame, and then rolls up to a calendar DATE for the daily grouping. Each cast names one step of the pipeline. A shorter chain like '2024-06-15 22:45:00+00'::timestamptz::date would land at the same destination type, and the grader checks the destination type rather than the intermediate steps, so a shorter form would pass. The full three-step chain is the canonical spelling because it makes the per-layer information loss explicit.
The trap
The session time zone enters the picture at the second cast. TIMESTAMPTZ stores UTC; converting it to TIMESTAMP uses the session zone to decide what wall-clock reading to record. A query run from a UTC session and a query run from an Eastern session produce different intermediate TIMESTAMP values, and when the recorded UTC time straddles midnight in the target zone, the final DATE lands on a different calendar day. The query that looks deterministic is only deterministic up to the session's zone setting. When a daily report has to be reproducible across sessions, the conversion zone needs to be made explicit somewhere in the pipeline; the chained-cast form here defers that decision to the session, which is the behavior the engineering team is verifying.
You practiced chained casting TIMESTAMPTZ-to-TIMESTAMP-to-DATE — each cast strips a layer of information until only the calendar date remains.