Cleaning invalid dates
The date_first_observed
column in the parking_violation
dataset represents the date when the parking violation was first observed by the individual recording the violation. Unfortunately, not all date_first_observed
values were recorded properly. Some records contain a '0'
value for this column. A '0'
value cannot be interpreted as a DATE
automatically as its meaning in this context is ambiguous. The column values require cleaning to enable conversion to a proper DATE
column.
In this exercise, you will convert the date_first_observed
value of records with a '0'
date_first_observed
value into NULL
values using the NULLIF()
function, so that the field can be represented as a proper date.
This exercise is part of the course
Cleaning Data in PostgreSQL Databases
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
-- Replace '0' with NULL
___(___, ___) AS date_first_observed
FROM
parking_violation;