Skip to content
Advertisement

optionally enclosed not working, commas breaking upload

I have this table:

Here is my load statement:

In spend I’ll have a decimal value with a comma like: 1193.72.

The spend field gets uploaded as 1. The impressions field that follows is correct and unaffected.

Example record: 1/19/2021 | 1,193.72 | 92780

Output: 1/19/2021 | 1 | 92780

I was under the impression including optionally enclosed by '"' would solve this, and for other text fields it seems to work as expected, but here it’s causing me problems.

Advertisement

Answer

MySQL doesn’t support input of numeric literals formatted with thousands separators.

The best solution would be to pre-process your input file before you try to use LOAD DATA INFILE. Otherwise you could do this workaround:

This stores the spend value into a temporary variable, instead of directly into the column. A user-defined variable is always a string type. Then you can remove the commas from that string before assigning it to the numeric spend column.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement