I've been trying to load a csv file into mysql, and keep getting the data truncated warning for the last field in the csv.
The data is prepped with python, and I make sure that the string of the last field has length 13 (the declared field length in CREATE TABLE):
cleanField( row[ 17 ] )[0:12]
Any which way I measure len(cleanField( row[ 17 ] )[0:12])
, it's 13. When I print it out using $ cat customer.csv | awk -F"," '(NR==3621789){ print $17 }'
, one of the rows in the mysql warning, I still see a 13-char string.
But when I try the following, there seems to be a hint of hidden character. Any advice? Thanks.
$ cat customer.csv | awk -F"," '(NR==3621789){ print "<" $17 ">" }'
>PRSP_CATS_CO
Here's cleanField:
def cleanField(x):
x = re.sub( ' +' , ' ' , x )
try:
x.decode('ascii')
except UnicodeDecodeError:
x = unicode( x , "UTF-8")
x = unicodedata.normalize('NFKD', x ).encode('ascii', 'ignore')
else:
pass
# " ".join(x.split())
return x.replace(',','').replace('"','').replace("'",'').replace('\t','').replace('\n','').replace('\\','').replace('\s','')