我尝试导入一个(巨大的)csv文件,在第一列中包含一个hotel_id,我希望sql表中的数据类型是这个代码的整数;
load data local infile 'Images_20121121.csv' into table cimages fields terminated by '|' LINES terminated by '\n' (@var1, link, description) set hotel_id=CAST(@var1 AS UNSIGNED INTEGER);
但这不起作用(我得到一个无效的数据类型错误),有什么想法吗?
CSV 文件的格式如下;
ˇ˛hotelid|url|description
4052465|https://carsolizeprod.blob.core.windows.net/images/hotels/a7ce966f-1c8d-4cdb-8050-0000132d2561.jpeg|
4020907|https://carsolizeprod.blob.core.windows.net/images/hotels/7230b738-4746-4751-8212-0000171a99c5.jpeg|
4263993|https://services.carsolize.com/images/hotels/f7f27005-3546-4347-8e18-000021a66962.jpeg|Exterior
4136518|https://services.carsolize.com/images/hotels/30ba8994-acd9-4993-9f74-0000359c309b.jpeg|Guest room
4305893|https://services.carsolize.com/images/hotels/c960b56a-bba6-4256-a0cd-00003f4be196.jpeg|Bar
4023461|https://services.carsolize.com/images/hotels/30388432-ffd2-4b2d-bb86-0000489cfbcf.jpeg|
4205330|https://services.carsolize.com/images/hotels/7473dde7-e7e3-4228-ab1d-000049e7ecfe.jpeg|
我得到的警告是;
| Warning | 1292 | Truncated incorrect INTEGER value: '' |
更新:我发现实际导入的 varchar 字段在每个字符之间包含一个 nul 值,所以这可能是问题所在(?)(查看二进制中的值,每个字符之间都有一个 00 字段,因为它是文本aNULbNULcNUL 我怎样才能避免这种情况?