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

问题描述 投票:0回答:2

来自如下所示的 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
正常值的查询,并且数据也无法在应用程序视图中正确显示。我很困惑 - 这是我做错了什么,还是 Cloud SQL 出了问题?!

mysql csv google-cloud-platform google-cloud-sql
2个回答
1
投票

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

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

0
投票

CSV 文件数据格式错误。

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

© www.soinside.com 2019 - 2024. All rights reserved.