将 .csv 文件导入 sqlite3 db 表 [英] Importing .csv file to sqlite3 db table
问题描述
我编写了一个单行 shell 脚本来将一个 .csv 文件导入到 sqlite3 数据库表中.
I wrote a single line shell script to import a .csv file to sqlite3 database table.
echo -e '.separator "," \n.import testing.csv aj_test' | sqlite3 ajtest.db
sqlite3 数据库 = ajtest.dbajtest.db 中的 sqlite3 表 = new_test
sqlite3 database = ajtest.db sqlite3 table in ajtest.db = new_test
testing.csv 有 3 列,第一列是 int 其余两列是文本;所以相应地,new_test 的结构也是--
the testing.csv has 3 columns, first one is int the rest two are texts; so accordingly the structure of new_test is also--
sqlite> .schema aj_test
CREATE TABLE aj_test(number integer not null,
first_name varchar(20) not null,
last_name varchar(20) not null);
当脚本运行时,它不会显示任何错误,但它也不会导入任何数据.关于我错过了什么的任何指导???
when the script is run, it does not show any error, but it also does not import any data. any guidelines as to what I have missed ???
推荐答案
经过大量研究和讨论,我找到了一个可以正常工作的答案,
After much studies and discussion, I found an answer that is working properly,
echo -e ".separator ","\n.import /home/aj/ora_exported.csv qt_exported2" | sqlite3 testdatabase.db
最重要的是,我需要在导入语句中包含 .csv 文件的路径.
the main thing is, that I needed to include the path of the .csv file in the import statement.
这篇关于将 .csv 文件导入 sqlite3 db 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!