本文介绍了如何将CSV文件中的引用数据导入SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更好的进步:
nicholas@mordor:~/csv$
nicholas@mordor:~/csv$ sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
sqlite> .import BCCDC_COVID19_Dashboard_Case_Details.csv details
...
BCCDC_COVID19_Dashboard_Case_Details.csv:25475: unescaped " character
BCCDC_COVID19_Dashboard_Case_Details.csv:25475: unescaped " character
sqlite>
sqlite> select * from details limit 3;
2020-01-26","Out of Canada","M","40-49","Lab-diagnosed
2020-02-02","Vancouver Coastal","F","50-59","Lab-diagnosed
2020-02-05","Out of Canada","F","20-29","Lab-diagnosed
sqlite>
sqlite> select "AGE_Group" from details limit 3;
AGE_Group
AGE_Group
AGE_Group
sqlite>
感谢下面的答案.
如何将此数据导入sqlite
:
nicholas@mordor:~/csv$
nicholas@mordor:~/csv$ sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
sqlite> .mode csv
sqlite>
sqlite> .import BCCDC_COVID19_Dashboard_Case_Details.csv details;
CREATE TABLE details;(...) failed: near ";": syntax error
sqlite> .quit
nicholas@mordor:~/csv$
nicholas@mordor:~/csv$ head BCCDC_COVID19_Dashboard_Case_Details.csv
"Reported_Date","HA","Sex","Age_Group","Classification_Reported"
"2020-01-26","Out of Canada","M","40-49","Lab-diagnosed"
"2020-02-02","Vancouver Coastal","F","50-59","Lab-diagnosed"
"2020-02-05","Out of Canada","F","20-29","Lab-diagnosed"
"2020-02-05","Out of Canada","M","30-39","Lab-diagnosed"
"2020-02-11","Interior","F","30-39","Lab-diagnosed"
"2020-02-20","Fraser","F","30-39","Lab-diagnosed"
"2020-02-21","Fraser","M","40-49","Lab-diagnosed"
"2020-02-27","Vancouver Coastal","F","60-69","Lab-diagnosed"
"2020-02-28","Vancouver Coastal","F","30-39","Lab-diagnosed"
nicholas@mordor:~/csv$
引号似乎有问题.
我还尝试了不同的模式和其他设置:
I've also tried different modes and other settings:
sqlite>
sqlite> .mode ascii
sqlite> .separator ","
sqlite>
没有成功.引用通用文档.
也许:
将使用csvsql
工具.
推荐答案
双引号不是问题.问题是;
.点命令不以分号;
终止.命令行将分号解释为表名的一部分.
It's not a problem with double-quotes. The problem is ;
. dot-commands are not terminated with a semi-colon ;
. The command line is interpreting the semi colon as part of the table name.
这篇关于如何将CSV文件中的引用数据导入SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!