如何使用SQLite3导入tsv文件 [英] How to import a tsv file with SQLite3

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

问题描述

我有一个想用sqlite3导入的tsv(制表符分隔的文件).有人知道这样做的明确方法吗?

I have a tsv (tab separated file) that I would like to import with sqlite3. Does someone know a clear way to do it?

我已经安装了sqlite3,但尚未创建任何数据库或表.

I have installed sqlite3, but not created any database or tables yet.

我已经尝试过命令

.import /path/filename.tsv my_new_table

但是它给了我错误:没有这样的表:my_new_table.

but it gives me the error: no such table: my_new_table.

但是,据我所读,如果表不存在,它应该自动创建表.这是否意味着我需要先创建和使用数据库,还是将.tsv文件导入sqlite的另一个技巧?

However, from what I'd read it should create the table automatically if it does't exist. Does it mean I need to create and use a database first, or is there another trick to importing a .tsv file into sqlite?

推荐答案

您应该创建表,设置分隔符并导入数据

You should create the table, set a separator and import the data sqlite wiki.

TSV示例:

data.tsv(以制表符作为分隔符):

data.tsv (tab as a separator):

Bob 30  1000
Wendy   20  900

1)创建一个表并将TAB设置为分隔符:

1) Create a table and set TAB as a separator:

sqlite> create table people (name text, param1 int, param2 int);
sqlite> .separator "\t"

2)导入数据:

sqlite> .import data.tsv people

结果是:

sqlite> select * from people;
Bob 30  1000
Wendy   20  900

这篇关于如何使用SQLite3导入tsv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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