SQLite无法识别列名

ux6nzvsh  于 2023-03-03  发布在  SQLite
关注(0)|答案(1)|浏览(167)

我从https://www.catalogueoflife.org/data/download下载了ColDP归档文件,并将NameUsage.tsv导入到一个SQLite表中,我认为该表大约有200万行。
创建表格:

.mode tabs
.import NameUsage.tsv name_usage

表模式

sqlite> .schema name_usage 
CREATE TABLE IF NOT EXISTS "name_usage"(
  "col:ID   col:alternativeID   col:nameAlternativeID   col:sourceID    col:parentID    col:basionymID  col:status  col:scientificName  col:authorship  col:rank    col:notho   col:uninomial   col:genericName col:infragenericEpithet col:specificEpithet col:infraspecificEpithet    col:cultivarEpithet col:namePhrase  col:nameReferenceID col:publishedInYear col:publishedInPage col:publishedInPageLink col:code    col:nameStatus  col:accordingToID   col:accordingToPage col:accordingToPageLink col:referenceID col:scrutinizer col:scrutinizerID   col:scrutinizerDate col:extinct col:temporalRangeStart  col:temporalRangeEnd    col:environment col:species col:section col:subgenus    col:genus   col:subtribe    col:tribe   col:subfamilycol:family col:superfamily col:suborder    col:order   col:subclass    col:class   col:subphylum   col:phylum  col:kingdom col:sequenceIndex   col:branchLength    col:link    col:nameRemarks col:remarks" TEXT
);

看起来创建的表有一个很长的列,该列由所有单独的列名组成。该列的类型已设置为 * TEXT
我很想去掉所有名称上的 * col:
前缀,也想选择不同列的类型。如果行数较少,我可能会在vim中编辑它,然后创建表,但不知道最佳方法是什么,加上大量的行,让我觉得最好是得到一些关于将数据放入SQLite表的最佳方法的建议。

    • 编辑:**

NameUsage.tsv的前几行

col:ID  col:alternativeID       col:nameAlternativeID   col:sourceID    col:parentID    col:basionymID  col:status      col:scientificName      col:authorship  col:rank        col:notho       col:uninomial   col:genericName col:infragenericEpithet col:specificEpithet     col:infraspecificEpithet        col:cultivarEpithet     col:namePhrase  col:nameReferenceID     col:publishedInYear     col:publishedInPage     col:publishedInPageLink col:code        col:nameStatus  col:accordingToID       col:accordingToPage     col:accordingToPageLink col:referenceID col:scrutinizer col:scrutinizerID       col:scrutinizerDate     col:extinct     col:temporalRangeStart  col:temporalRangeEnd    col:environment col:species     col:section     col:subgenus    col:genus       col:subtribe    col:tribe       col:subfamily   col:family      col:superfamily col:suborder    col:order       col:subclass    col:class       col:subphylum   col:phylum      col:kingdom     col:sequenceIndex       col:branchLength        col:link        col:nameRemarks col:remarks
5T6MX                                           accepted        Biota           unranked                Biota                                                                                           acceptable                                      CoL                                                                                                                                                            
5SY                             HP              accepted        Velocipedoidea          superfamily             Velocipedoidea                                                                                                                                                                                                                                                                                         
3FD8
    • 编辑:**
head -3 NameUsage.tsv | cat -A
col:ID^Icol:alternativeID^Icol:nameAlternativeID^Icol:sourceID^Icol:parentID^Icol:basionymID^Icol:status^Icol:scientificName^Icol:authorship^Icol:rank^Icol:notho^Icol:uninomial^Icol:genericName^Icol:infragenericEpithet^Icol:specificEpithet^Icol:infraspecificEpithet^Icol:cultivarEpithet^Icol:namePhrase^Icol:nameReferenceID^Icol:publishedInYear^Icol:publishedInPage^Icol:publishedInPageLink^Icol:code^Icol:nameStatus^Icol:accordingToID^Icol:accordingToPage^Icol:accordingToPageLink^Icol:referenceID^Icol:scrutinizer^Icol:scrutinizerID^Icol:scrutinizerDate^Icol:extinct^Icol:temporalRangeStart^Icol:temporalRangeEnd^Icol:environment^Icol:species^Icol:section^Icol:subgenus^Icol:genus^Icol:subtribe^Icol:tribe^Icol:subfamily^Icol:family^Icol:superfamily^Icol:suborder^Icol:order^Icol:subclass^Icol:class^Icol:subphylum^Icol:phylum^Icol:kingdom^Icol:sequenceIndex^Icol:branchLength^Icol:link^Icol:nameRemarks^Icol:remarks$
5T6MX^I^I^I^I^I^Iaccepted^IBiota^I^Iunranked^I^IBiota^I^I^I^I^I^I^I^I^I^I^I^Iacceptable^I^I^I^I^ICoL^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I$
5SY^I^I^I^IHP^I^Iaccepted^IVelocipedoidea^I^Isuperfamily^I^IVelocipedoidea^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I$
k2arahey

k2arahey1#

确保TSV文件包含一个标题,标题中列的名称正确。另外,检查字段是否正确地用制表符分隔,而不是空格。
在您的示例中,字段包含“col:”前缀,因此当sqlite将第一行解析为标题时,它使用这些名称。关于创建单个 TEXT 列,字段可能由空格而不是制表符分隔。
另一种选择是先创建表:

create table name_usage (
  ID int,
  alternativeID  int,
  ...
);

虽然导入是自动进行的,但是您不能选择列的类型(它们可能会被加载为 TEXT)。
然后,您可以使用相同的方法进行导入:

.mode tabs
.import NameUsage.tsv name_usage

或将制表符设置为分隔符:

.separator "\t"
.import NameUsage.tsv name_usage

注意,在第二个选项中,sqlite仍然使用csv样式的规则来解释引号,这可能不是您想要的,因此,推荐使用第一个选项。

相关问题