I have a CSV file with datetime values like ‘2020-02-02 04:00:00.0000000’ when I try to convert/cast these to TIMESTAMPS I get really weird results. Sometimes the TO_TIMESTAMP return NULLs when CAST as TIMESTAMP returns the correct result.
Query:
SELECT
ContainerVisitID,
DepartureTime,
LEFT(DepartureTime, LENGTH(DepartureTime) - 4) as DepTimeTrimmedText,
TO_TIMESTAMP(LEFT(DepartureTime, LENGTH(DepartureTime) - 4), 'YYYY-MM-DD HH:MI:SS.FFF', 1) as DepTimeToTimeStamp,
CAST(LEFT(DepartureTime, LENGTH(DepartureTime) - 4) AS TIMESTAMP) as "DepTimeCast"
FROM "MCT Data Lake".raw.TOS.ContainerVisit
LIMIT 100
Result: