Brightlane's data engineering team is verifying that plain date strings parse cleanly to the calendar-date type during import.
Write a query to return the string '1992-04-18' cast as a calendar date.
Output:
- A single row with one column,
birth_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
'1992-04-18'::date AS birth_date The shape
The ::date cast tells PostgreSQL to resolve '1992-04-18' as a calendar date rather than as the text it would otherwise be. A birth date has no time-of-day and no time zone, which is exactly what DATE stores.
Clause by clause
SELECT '1992-04-18'::date AS birth_dateevaluates the literal once and returns it as a singleDATEvalue. The::datecast is the load-bearing part: without it, PostgreSQL would resolve the literal astext, and the output column would carry the wrong type even though the displayed string looks identical.- There is no
FROMbecause no table is being read; the value comes directly from the literal in theSELECTlist.
Why the explicit cast
A bare '1992-04-18' is just a string. PostgreSQL will display it the same way in a result row, but downstream consumers that expect a date column will see text and either error out or coerce silently. The ::date cast resolves the ambiguity at write time and locks the column's type to DATE. The alternate spelling CAST('1992-04-18' AS date) produces the same result; pick whichever reads more naturally in context.
You practiced casting a calendar-only string to DATE with ::date — the right type for values that have no time-of-day component.