mysqlcsvgoogle-cloud-platformgoogle-cloud-sql

Google Cloud MySQL Truncating Timestamps from CSV Import


From a CSV that looks like:

2018-01-18 13:23:48.878,KERRIE PAUSSA,CLOCK IN LUNCH
2018-01-18 16:57:46.466,ANDREW PEDERSON,CLOCK OUT PM
2018-01-18 17:29:57.731,AARON RICHARDS,CLOCK OUT PM
2018-01-18 17:30:11.903,DANIEL PURBRICK,CLOCK OUT PM

Google Cloud SQL is rendering:

Timestamp           | Name       | Punch_Type       | id   |
+---------------------+------------+------------------+------+
| 2018-01-18 06:59:15 | FRED MOORE | CLOCK IN AM      | 3427 |
| 2018-01-18 12:00:43 | FRED MOORE | CLOCK OUT LUNCH  | 3433 |
| 2018-01-18 12:32:03 | FRED MOORE | CLOCK IN LUNCH   | 3437 |
    | 3484 | 17:38:28 | FRED MOORE | CLOCK OUT PM
     | 3490 |06:59:18 | FRED MOORE | CLOCK IN AM
 | 3498 |-22 12:23:04 | FRED MOORE | CLOCK OUT LUNCH
  | 3504 |22 12:54:40 | FRED MOORE | CLOCK IN LUNCH
+---------------------+------------+------------------+------+

However, when only the Timestamp column is selected, the data appear normal:

+---------------------+
| Timestamp           |
+---------------------+
| 2018-01-18 06:59:15 |
| 2018-01-18 12:00:43 |
| 2018-01-18 12:32:03 |
| 2018-01-18 17:38:28 |
| 2018-01-22 06:59:18 |
| 2018-01-22 12:23:04 |
| 2018-01-22 12:54:40 |
+---------------------+

This is the only query that returns normal values for Timestamp, though, and the data aren't displaying properly in the application view either. I'm flummoxed - is this something I've done wrong, or something wonky with Cloud SQL?!


Solution

  • Turns out this was a carriage return /r character at the end of each line. Very annoying! TRIM worked great:

    update Daily_clock_totals SET Punch_Type = TRIM(TRAILING '\r' FROM Punch_Type);