gpt4 book ai didi

MySQL 加载数据 infile ("NULL"CSV 中日期时间的字符串)

转载 作者:行者123 更新时间:2023-11-29 01:03:24 24 4
gpt4 key购买 nike

您好,我有以下 CSV 格式

id   (tab)  creation_date
-------------------------
1 2012-05-04 15:26:45.000
2 NULL

对于我正在使用的导入:

load data local infile './test.csv' into table TEST fields terminated by '\t'
lines terminated by '\n'
IGNORE 1 LINES
(id,@creation_date)
SET
creation_date = nullif(@creation_date,'NULL');

但不幸的是,NULL 值 (String) 未被解释并在列中设置为 NULL。相反,我收到有关数据截断的警告,并插入默认日期 0000-00-00....

我如何检查:是 String = "NULL"然后将 NULL 插入到列中?

最佳答案

documentation根据您使用的查询字段和行,有关于如何在文件中解释 NULL 的规则,简单来说:

  • If FIELD and LINES is default values in your query use \N (NO QUOTES).
  • If FIELD ENCLOSED BY and/or FIELD ESCAPED BY is used, use the word NULL (NO QUOTES).
  • With fixed-row format (which is used when FIELDS TERMINATED BY and FIELDS ENCLOSED BY are both empty), NULL is written as an empty string i.e. "".

您的用例是第一个项目符号。

**从底部段落中的文档中阅读更多内容 NULL 值的处理根据所使用的 FIELDS 和 LINES 选项而有所不同: 上面的部分链接。

关于MySQL 加载数据 infile ("NULL"CSV 中日期时间的字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22300228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com