Wednesday, October 11, 2017

[google-cloud-sql-discuss] Export from MySQL to csv and then import from the same file alters data

I have a table with a nullable column:

    CREATE TABLE test (id INT, value INT);
    INSERT INTO test VALUES (1, null);

I export it to csv using export button in web console. It generates the following query:

    SELECT * FROM `test`.`test`
    INTO OUTFILE '...' 
    CHARACTER SET 'utf8' 
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY '"' 
    ESCAPED BY '"'

The output file looks like this:

    1,"N

Then I truncate table and import it, with import button in web console:

    LOAD DATA LOCAL INFILE '...' 
    INTO TABLE `test`.`test` 
    CHARACTER SET 'utf8' 
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY '"' 
    ESCAPED BY '"';

And it changes all null INTs to 0, and null VARCHARs to `"N`. If I try to import this file manually using the same query I get the following warning:

    SHOW WARNINGS;
    Warning 1366: Incorrect integer value: '"N' for column 'value' at row 1

For some reason escaping doesn't work for this case. It does work if fields are escaped and enclosed by different symbols but there is no such option in export dialog. Am I doing something wrong?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/14d6f568-540b-483d-b8cd-7d1dd8c76e51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment