错误1062(23000):重复条目虽然条目不重复

时间:2016-02-08 15:07:38

标签: mysql

表格定义:

CREATE TABLE PositionalDataNGS ( Date DATE, Time TIME(3) , X FLOAT(5), Y FLOAT(5), D FLOAT(5) , V FLOAT(5),  OnField BOOL, GameID_GSIS INT, TeamID INT, PlayerID_GSIS CHAR(10), PRIMARY KEY(Time) );

这会创建所需的表,我需要用以下条目填充它:

    Data, Time, X, Y, D, V, OnFeild, GameID, TeamID,  PlayerID_GSIS  
 2015-11-15 ,17:56:45.300 ,  93.32,  8.6,  4.57,  0.45 , true,   2015111500  , 5110  , 22-0026189 
 2015-11-15 ,17:56:45.400 ,  93.77,  8.48,  4.55,  0.47 , true,   2015111500  , 5110  , 02-0022289 
 2015-11-15 ,17:56:45.500 ,  94.23,  8.36,  4.53,  0.47 , true,   2015111500  , 5110  , 03-0026179 
 2015-11-15 ,17:56:45.600 ,  94.67,  8.23,  4.51,  0.46 , true,   2015111500  , 5110  , 30-0026180 

显然,时间不重复,但在尝试将csv表填充到数据库时:

LOAD DATA INFILE "/PositionalDataNGS_2.csv" INTO TABLE PositionalDataNGS COLUMNS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES;

我收到此错误: ERROR 1062(23000):对于'PRIMARY'键重复输入'17:56:45.300'

这是MySQL 5.6.28所以它应该能够处理几分之一秒的时间。谢谢!

1 个答案:

答案 0 :(得分:2)

我无法重现这个问题。在文件PositionalDataNGS_2.csv中没有重复的值?

测试:

mysql> SELECT VERSION();
+-------------------------+
| VERSION()               |
+-------------------------+
| 5.6.28                  |
+-------------------------+
1 row in set (0.00 sec)

mysql> DROP TABLE IF EXISTS `PositionalDataNGS`;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE `PositionalDataNGS`(
    ->   `Date` DATE,
    ->   `Time` TIME(3),
    ->   `X` FLOAT(5),
    ->   `Y` FLOAT(5),
    ->   `D` FLOAT(5),
    ->   `V` FLOAT(5),
    ->   `OnField` BOOL,
    ->   `GameID_GSIS` INT,
    ->   `TeamID` INT,
    ->   `PlayerID_GSIS` CHAR(10),
    ->   PRIMARY KEY(`Time`)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO `PositionalDataNGS` (
    ->   `Date`,
    ->   `Time`,
    ->   `X`,
    ->   `Y`,
    ->   `D`,
    ->   `V`,
    ->   `OnField`,
    ->   `GameID_GSIS`,
    ->   `TeamID`,
    ->   `PlayerID_GSIS`
    -> )
    -> VALUES
    -> ('2015-11-15', '17:56:45.300', 93.32, 8.6, 4.57, 0.45, true, '2015111500', 5110, '22-0026189'),
    -> ('2015-11-15', '17:56:45.400', 93.77, 8.48, 4.55, 0.47, true, '2015111500', 5110, '02-0022289'),
    -> ('2015-11-15', '17:56:45.500', 94.23, 8.36, 4.53, 0.47, true, '2015111500', 5110, '03-0026179'),
    -> ('2015-11-15', '17:56:45.600', 94.67, 8.23, 4.51, 0.46, true, '2015111500', 5110, '30-0026180');
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> SELECT
    ->   `Date`,
    ->   `Time`,
    ->   `X`,
    ->   `Y`,
    ->   `D`,
    ->   `V`,
    ->   `OnField`,
    ->   `GameID_GSIS`,
    ->   `TeamID`,
    ->   `PlayerID_GSIS`
    -> FROM
    ->   `PositionalDataNGS`;
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
| Date       | Time         | X     | Y    | D    | V    | OnField | GameID_GSIS | TeamID | PlayerID_GSIS |
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
| 2015-11-15 | 17:56:45.300 | 93.32 |  8.6 | 4.57 | 0.45 |       1 |  2015111500 |   5110 | 22-0026189    |
| 2015-11-15 | 17:56:45.400 | 93.77 | 8.48 | 4.55 | 0.47 |       1 |  2015111500 |   5110 | 02-0022289    |
| 2015-11-15 | 17:56:45.500 | 94.23 | 8.36 | 4.53 | 0.47 |       1 |  2015111500 |   5110 | 03-0026179    |
| 2015-11-15 | 17:56:45.600 | 94.67 | 8.23 | 4.51 | 0.46 |       1 |  2015111500 |   5110 | 30-0026180    |
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
4 rows in set (0.00 sec)

<强>更新

档案:PositionalDataNGS_2.csv

Data,Time,X,Y,D,V,OnFeild,GameID,TeamID,PlayerID_GSIS
2015-11-15,17:56:45.300,93.32,8.6,4.57,0.45,true,2015111500,5110,22-0026189
2015-11-15,17:56:45.400,93.77,8.48,4.55,0.47,true,2015111500,5110,02-0022289
2015-11-15,17:56:45.500,94.23,8.36,4.53,0.47,true,2015111500,5110,03-0026179
2015-11-15,17:56:45.600,94.67,8.23,4.51,0.46,true,2015111500,5110,30-0026180

MySQL的:

mysql> TRUNCATE TABLE `PositionalDataNGS`;
Query OK, 0 rows affected (0.00 sec)

mysql> LOAD DATA INFILE '/path/to/file/PositionalDataNGS_2.csv'
    ->   INTO TABLE `PositionalDataNGS`
    ->   COLUMNS TERMINATED BY ','
    ->   LINES TERMINATED BY '\n'
    ->   IGNORE 1 LINES;
Query OK, 4 rows affected, 4 warnings (0.01 sec)
Records: 4  Deleted: 0  Skipped: 0  Warnings: 4

mysql> SHOW WARNINGS;
+---------+------+---------------------------------------------------------------+
| Level   | Code | Message                                                       |
+---------+------+---------------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: 'true' for column 'OnField' at row 1 |
| Warning | 1366 | Incorrect integer value: 'true' for column 'OnField' at row 2 |
| Warning | 1366 | Incorrect integer value: 'true' for column 'OnField' at row 3 |
| Warning | 1366 | Incorrect integer value: 'true' for column 'OnField' at row 4 |
+---------+------+---------------------------------------------------------------+

mysql> SELECT
    ->   `Date`,
    ->   `Time`,
    ->   `X`,
    ->   `Y`,
    ->   `D`,
    ->   `V`,
    ->   `OnField`,
    ->   `GameID_GSIS`,
    ->   `TeamID`,
    ->   `PlayerID_GSIS`
    -> FROM
    ->   `PositionalDataNGS`;
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
| Date       | Time         | X     | Y    | D    | V    | OnField | GameID_GSIS | TeamID | PlayerID_GSIS |
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
| 2015-11-15 | 17:56:45.300 | 93.32 |  8.6 | 4.57 | 0.45 |       0 |  2015111500 |   5110 | 22-0026189    |
| 2015-11-15 | 17:56:45.400 | 93.77 | 8.48 | 4.55 | 0.47 |       0 |  2015111500 |   5110 | 02-0022289    |
| 2015-11-15 | 17:56:45.500 | 94.23 | 8.36 | 4.53 | 0.47 |       0 |  2015111500 |   5110 | 03-0026179    |
| 2015-11-15 | 17:56:45.600 | 94.67 | 8.23 | 4.51 | 0.46 |       0 |  2015111500 |   5110 | 30-0026180    |
+------------+--------------+-------+------+------+------+---------+-------------+--------+---------------+
4 rows in set (0.00 sec)