How to import a tsv file with SQLite3

前端 未结 2 1560
梦毁少年i
梦毁少年i 2020-12-08 04:05

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

I have installed sqlite3, but not created any dat

相关标签:
2条回答
  • 2020-12-08 04:47

    There is actually a dedicated mode for importing tab separated files:

    sqlite> .mode tabs
    sqlite> .import data.tsv people
    

    Also if you include a header row in your tsv file, you can let sqlite automatically create the table. Just use an unused table-name during import and change the tsv file to:

    name    param1  param2
    Bob 30  1000
    Wendy   20  900
    
    0 讨论(0)
  • 2020-12-08 04:52

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

    Example for TSV:

    data.tsv (tab as a separator):

    Bob 30  1000
    Wendy   20  900
    

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

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

    2) Import data:

    sqlite> .import data.tsv people
    

    And the result is:

    sqlite> select * from people;
    Bob 30  1000
    Wendy   20  900
    
    0 讨论(0)
提交回复
热议问题