i'm importing 1m+ records into my table from a csv file. Works great using the load data local infile method.
However, the dates are all different formats. A quick google lead me to this function:
STR_TO_DATE
However, when I implement that, I get nothing, an empty insert. here's my SQ cut down to include one date (I've 4 with the same issue) and generic column names:
load data local infile 'myfile.csv' into table `mytable`
fields terminated by '\t'
lines terminated by '\n'
IGNORE 1 LINES
( `column name 1`
, `my second column`
, @temp_date
, `final column`)
SET `Get Date` = STR_TO_DATE(@temp_date, '%c/%e/%Y')
If I do:
SET `Get Date` = @temp_date
The date from the csv is captured in the the format it was in the file. However when I try the first method, my table column is empty. I've changed the column type to varchar (255) from timestamp to captre whatever is going in, but ultimatly, I want to capture y-m-d H:i:s (Not sure if STR_TO_DATE can do that?)
I'm also unsure as to why I need the @ symbol.. google failed me there.
So, my questions are:
- Why do I need the @ symbol to use this function?
- Should the data format ('%c/%e/%Y') be the format of the inputted data or my desired output?
- Can I capture time in this way too?
sorry for the large post!
Back to Google for now...