Open davidshiz opened 1 year ago
It seems we need to convert numeric data to binary derectly.
assigned me
Meet any problems here? @TomeC
The method on load bit
data is different with other types, ref:
https://github.com/stoneatom/stonedb/blob/stonedb-5.7-dev/mysql-test/suite/tianmu/t/bit_type.test#L115
Ref from mysql docs: https://dev.mysql.com/doc/refman/8.0/en/load-data.html
BIT values cannot be loaded directly using binary notation (for example, b'011010'). To work around this, use the SET clause to strip off the leading b' and trailing ' and perform a base-2 to base-10 conversion so that MySQL loads the values into the BIT column properly:
$> cat /tmp/bit_test.txt
b'10'
b'1111111'
$> mysql test
mysql> LOAD DATA INFILE '/tmp/bit_test.txt'
INTO TABLE bit_test (@var1)
SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-3), 2, 10) AS UNSIGNED);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> SELECT BIN(b+0) FROM bit_test;
+----------+
| BIN(b+0) |
+----------+
| 10 |
| 1111111 |
+----------+
2 rows in set (0.00 sec)
For BIT values in 0b binary notation (for example, 0b011010), use this SET clause instead to strip off the leading 0b:
SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-2), 2, 10) AS UNSIGNED)
Meet any problems here? @TomeC The method on load
bit
data is different with other types, ref: https://github.com/stoneatom/stonedb/blob/stonedb-5.7-dev/mysql-test/suite/tianmu/t/bit_type.test#L115Ref from mysql docs: https://dev.mysql.com/doc/refman/8.0/en/load-data.html
BIT values cannot be loaded directly using binary notation (for example, b'011010'). To work around this, use the SET clause to strip off the leading b' and trailing ' and perform a base-2 to base-10 conversion so that MySQL loads the values into the BIT column properly:
$> cat /tmp/bit_test.txt b'10' b'1111111' $> mysql test mysql> LOAD DATA INFILE '/tmp/bit_test.txt' INTO TABLE bit_test (@var1) SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-3), 2, 10) AS UNSIGNED); Query OK, 2 rows affected (0.00 sec) Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 mysql> SELECT BIN(b+0) FROM bit_test; +----------+ | BIN(b+0) | +----------+ | 10 | | 1111111 | +----------+ 2 rows in set (0.00 sec)
For BIT values in 0b binary notation (for example, 0b011010), use this SET clause instead to strip off the leading 0b:
SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-2), 2, 10) AS UNSIGNED)
Thank you for the document,The current progress:
select ... into outfile
has been solved.
Have you read the Contributing Guidelines on issues?
Please confirm if bug report does NOT exists already ?
Describe the problem
After OUTFILE the BIT data, then LOAD the data, the results are inconsistent
Expected behavior
No response
How To Reproduce
Environment
Are you interested in submitting a PR to solve the problem?