将 CSV 导入 SQLite [英] Import CSV to SQLite

查看:59
本文介绍了将 CSV 导入 SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 csv 文件导入 SQLite 表.

I'm trying to import a csv file to an SQLite table.

示例 csv:

1,2
5,6
2,7

示例命令:

sqlite> create table foo(a, b);
sqlite> .separator ,
sqlite> .import test.csv foo
Error: test.csv line 1: expected 2 columns of data but found 4

我什至不知道为什么它会找到包含 6 条数据和 2 列的四列.

I'm not even sure why it would find four columns with six pieces of data and two columns.

推荐答案

评论中也提到了什么,SQLite 将您的输入视为 1, 25, 62, 7.我也遇到了问题,就我而言它是通过将分隔符"更改为.mode csv"来解决的.所以你可以试试:

What also is being said in the comments, SQLite sees your input as 1, 25, 62, 7. I also had a problem with , and in my case it was solved by changing "separator ," into ".mode csv". So you could try:

sqlite> create table foo(a, b);
sqlite> .mode csv
sqlite> .import test.csv foo

第一个命令为表创建列名.但是,如果您希望从 csv 文件继承列名,您可以忽略第一行.

The first command creates the column names for the table. However, if you want the column names inherited from the csv file, you might just ignore the first line.

这篇关于将 CSV 导入 SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆