Google Cloud MySQL截断CSV导入的时间戳

时间:2018-01-23 00:38:30

标签: mysql csv google-cloud-platform google-cloud-sql

来自看似如下的CSV:

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正在渲染:

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
+---------------------+------------+------------------+------+

但是,仅选择Timestamp列时,数据显示正常:

+---------------------+
| 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 |
+---------------------+

这是唯一一个返回Timestamp正常值的查询,并且数据在应用程序视图中也没有正确显示。我感到很沮丧 - 这是我做错了什么,或者是云计算的东西吗?!

2 个答案:

答案 0 :(得分:1)

原来这是每行末尾的回车符/ r字符。很烦人! TRIM运作良好:

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

答案 1 :(得分:0)

CSV文件数据格式错误。

  

Cloud SQL接受的CSV文件的格式等同于使用MySQL语句“LOAD DATA INFILE ... CHARACTER SET'utf8'FIELDS TERMINATED BY','OPTIONALLY ENCLOSED by'\'''''''''''