开发者

Auto trim values for varchar on insert

开发者 https://www.devze.com 2023-04-11 05:53 出处:网络
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 \'f

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

精彩评论

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

关注公众号