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", " ")
;
精彩评论