Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Incomplete
-
10.3.9
-
RedHat 7.2
Description
We we try to load data from json file the escape characters dont get padded and the load fails.
DROP TABLE IF EXISTS mdb.dn; |
|
CREATE TABLE dn |
(
|
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, |
jsondata json,
|
check (json_valid(jsondata)) |
)
|
|
ALTER TABLE dn ADD an VARCHAR(100) AS (JSON_VALUE (jsondata, '$.an')); |
ALTER TABLE dn ADD modification_datetime BIGINT AS (JSON_VALUE (jsondata, '$.modification_datetime')); |
ALTER TABLE dn ADD body LONGTEXT AS (JSON_VALUE (jsondata, '$.body')); |
|
CREATE UNIQUE INDEX dn_an_modification_datetime_pk ON dn (an, modification_datetime); |
Sample row:
{"an" : "XXXXEDX", "modification_datetime" : 1535027267000, "body" : " This is a test \" I think it does not work\n However when we add an extra ba
|
ckslash escape, \n Then it works\n"}
|
load data local infile '/usr/local/mysql/scripts/dn.json' into table dn(jsondata); |
|
load data local infile '/usr/local/mysql/scripts/dn.json' into table dn(jsondata); |
Query OK, 0 rows affected, 1 warning (0.000 sec) |
Records: 0 Deleted: 0 Skipped: 0 Warnings: 1
|
|
MariaDB[mdb]> show warnings;
|
+---------+------+-----------------------------------------------------+ |
| Level | Code | Message | |
+---------+------+-----------------------------------------------------+ |
| Warning | 4025 | CONSTRAINT `CONSTRAINT_1` failed for `mdb`.`dn` | |
+---------+------+-----------------------------------------------------+ |
1 row in set (0.000 sec) |
{"an" : "XXXXEDX", "modification_datetime" : 1535027267000, "body" : " This is a test \\" I think it does not work\\n However when we add an extra ba
|
ckslash escape, \\n Then it works\\n"}
|
MariaDB [mdb]> load data local infile '/usr/local/mysql/scripts/dn.json' into table dn(jsondata); |
Query OK, 1 row affected (0.001 sec)
|
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
|
|
MariaDB [mdb]> select * from dn; |
+----+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+---------+-----------------------+ |
| id | jsondata | body | an | modification_datetime |
|
+----+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+---------+-----------------------+ |
| 1 | {"an" : "XXXXEDX", "modification_datetime" : 1535027267000, "body" : " This is a test \" I think it does not work\n However when we add an extra backslash escape, \n Then it works\n"} | This is a test " I think it does not work |
However when we add an extra backslash escape, |
Then it works |
| XXXXEDX | 1535027267000 |
|
+----+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+---------+-----------------------+ |
1 row in set (0.001 sec) |
Not sure how we can load the data as it come from the source like shown on the first sample line.}}