Modify column before inserting XML value to MySQL table -
i'm trying import xml file mysql table. in xml file there timestamp in <currenttime> in following format:
2016-01-26t09:52:19.3420655+01:00
this timstamp should go corresponding datetime currenttime column in table. did following
load xml infile 'xxx.xml' table test.events rows identified '<event>' set currenttime = str_to_date(currenttime, '%y-%m-%dt%h:%i:%s.%f');
but quits error
error code: 1292. incorrect datetime value: '2016-01-25t16:22:24.1840792+01:00' column 'currenttime' @ row 1
so seems doesn't convert string @ all. why?
i think error thrown when string value file loaded directly column. error thrown before set clause.
here's abbreviated example of how use user-defined variables pass value of field down set
, bypassing assignment column.
note columns _row
, account_number
populated directly first 2 fields in file. later fields in file assigned user-defined variables (identifiers beginning @
.
the set
clause evaluates user-defined variables, , assigns result of expression actual column in table.
in example, "dates" formatted yyyymmdd. used str_to_date()
function have string converted proper date
.
i abbreviated sample somewhat, demonstrates approach of reading field values user-defined variables.
create table _import_water (`_row` int ,`account_number` varchar(255) ,`total_due` decimal(18,2) ,`end_date` date ,`start_date` date ,`ccf` decimal(18,4) ) load data local infile '//server/share$/users/me/mydir/myfile.csv' table _import_water fields terminated ',' optionally enclosed '"' lines terminated '\r\n' ignore 1 lines (_row ,account_number ,@total_due ,@end_date ,@start_date ,@ccf ) set `total_due` = nullif(@total_due,'') , `end_date` = str_to_date(@end_date,'%y%m%d') , `start_date` = str_to_date(@start_date,'%y%m%d') , `ccf` = nullif(@ccf,'')
also, doesn't there's problem str_to_date
, seems evaluate fine.
testing...
select str_to_date('2016-01-25t16:22:24.1840792+01:00','%y-%m-%dt%h:%i:%s.%f') mydatetime
returns:
mydatetime -------------------------- 2016-01-25 16:22:24.184079
Comments
Post a Comment