简体   繁体   中英

How to use null as default value on a mysql decimal field with LOAD DATA?

I load a CSV file using LOAD DATA LOCAL INFILE . Some values eg for decimals are optional and thus not set in csv.

I tried both inserting a blank ,, in csv, and a ,null, . For both of them the mysql table shows a 0 as decimal value.

CREATE TABLE `my_table` (
     ...
    `price` decimal(10,2) DEFAULT NULL,
)

But why isn't the default value used if I leave the field blank during load?

Sidenote: the linked question is not an answer, as the comment accepted has nothing to do with the special null handling in mysql! Moreover, an acceptable answer to that question should state the solution as a oneliner, so everyone finds a quick solution. Which is also not the case in the linked "duplciate" question.

Found it: mysql is case sensitive here and expects a uppercase ,NULL, . Or ,\\N,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM