0

I am loading a local csv for a table in MySQL. The table has 6 columns (or fields), but, after I load the data, only the message_date column is filled. In other words, the other 5 columns in the table are all NULL, after the LOAD DATA run. Why? I need to SET all of the 5 columns to bring them to my table?

Detail: When I do not SET any variable, just import them all as character fields, all of the columns appears. So it looks like is something after the IGNORE statement that is affecting all of the other 5 columns.

LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/DadosBrutosEventTracks.csv'
    INTO TABLE messages
    FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n'
    IGNORE 1 LINES
    (@var1, @var2, @var3, @var4, @var5, @var6)
    SET 
    message_date = STR_TO_DATE(SUBSTRING(@var3, 1, 22), "%Y-%m-%d %H:%i:%s.%f");
1
  • Why? You load into either the column or the variable. not into both. Use (column1, column2, @var3, column4, column5, column6) SET message_date = STR_TO_DATE(SUBSTRING(@var3, 1, 22), "%Y-%m-%d %H:%i:%s.%f"). Commented Apr 12, 2021 at 16:42

1 Answer 1

2

You only load data into variables. Therefore no data goes into any columns. Loading data into variables happens instead of loading into columns.

(@var1, @var2, @var3, @var4, @var5, @var6)

Then you set one column:

SET 
message_date = STR_TO_DATE(SUBSTRING(@var3, 1, 22), "%Y-%m-%d %H:%i:%s.%f");

The other columns are not mentioned in the SET clause, so they get no data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.