Brightlane's data quality report displays the same business event stored in three different formats so engineers can compare how each type renders.
Write a query to return three columns in a single row: the string '2024-06-15' cast as a calendar date; '2024-06-15 09:00:00' cast as a timezone-naive timestamp; and '2024-06-15 09:00:00+05:30' cast as a timezone-aware timestamp.
Output:
- A single row with columns
just_date,local_ts, andabsolute_ts.
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'::date AS just_date,
'2024-06-15 09:00:00'::TIMESTAMP AS local_ts,
'2024-06-15 09:00:00+05:30'::TIMESTAMPTZ AS absolute_ts The shape
Three casts side by side put the same string-form value into three distinct types — DATE, TIMESTAMP, and TIMESTAMPTZ — so the engineers can read off how each type stores its input. Each cast is the only thing that distinguishes one column from the next; the literals themselves are nearly identical.
Clause by clause
SELECT '2024-06-15'::date AS just_dateresolves the calendar-only string toDATE. No time-of-day, no zone.'2024-06-15 09:00:00'::timestamp AS local_tsresolves the wall-clock string toTIMESTAMP. The value is stored as written; no zone information is attached or inferred.'2024-06-15 09:00:00+05:30'::timestamptz AS absolute_tsresolves the offset-bearing string toTIMESTAMPTZ. PostgreSQL reads the+05:30, converts the wall-clock reading to UTC at parse time, and stores the absolute moment that09:00in India corresponds to.- There is no
FROMbecause the values come directly from literals.
Why the explicit casts on every column
The grader checks each output column's type, not just its displayed value. '2024-06-15' looks like a date and '2024-06-15 09:00:00' looks like a timestamp, but both are text until a cast resolves them. Each column on the data-quality report has to land in the specific type it represents, and the ::date / ::timestamp / ::timestamptz casts are what make that happen. The destination type is the contract; the cast is what fulfills it.
The trap
The TIMESTAMP and TIMESTAMPTZ columns look interchangeable because their input strings differ only by the trailing offset. They are not interchangeable. local_ts records the clock reading with no zone; absolute_ts records a specific moment in UTC. The same business event written into one and then the other would compare unequal as soon as the session zone shifted. Choosing between the two is a semantic decision about whether the data represents a moment or a clock reading, and the cast is where that decision lands.
You practiced casting the same business moment into DATE, TIMESTAMP, and TIMESTAMPTZ side by side — three distinct types with three different storage semantics.