开发者

Auto trim values for varchar on insert

Is there an equivalent option to *SET ANSI_PADDING* from ms-sql for mysql, or another 开发者_开发技巧way to auto-trim values inserted to a varchar-field from a csv file with LOAD DATA LOCAL INFILE 'foo.csv' ?


You may manipulate imported files during LOAD DATA by using SET combined with one or multiple string functions. Here's an example that trims a column during import as well as removing any newlines

LOAD DATA LOCAL INFILE 'foo.csv' 
INTO TABLE db.footable
(foocolumn)
SET foocolumn = TRIM(foocolumn), 
foocolumn = REPLACE(foocolumn, "\n", " ") 
;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜