回答

收藏

通过命令导入csv的sqlite错误

技术问答 技术问答 280 人阅读 | 0 人回复 | 2023-09-14

$ sqlite3 test.sql
2 W+ T2 n6 ^6 n3 I; {7 t! U                SQLite version 3.6.125 J, y. T* b* j% a3 r7 F# x& }- ]; C" u
                Enter “.help” for instructions
) K8 \5 c- k/ L& h: {                Enter SQL statements terminated with a “;”
1 g4 L* K* k+ S" z: ?3 k                sqlite> create table test (id integer,author_id integer,title varchar(128),name text);
) o8 X! `$ p3 s9 J                sqlite> .separator “;”
3 Z6 f3 w1 d- X4 d' F                sqlite> .import sqlite.csv test
. l. f, _# Y+ C                sqlite.csv line 3: expected 4 columns of data but found 1$ d* Q1 r: \2 ~9 Y! C
                sqlite> .separator ‘;’4 v: M+ z2 q' q6 @6 F) E
                sqlite> .import sqlite.csv test* I# h# J+ q% f7 n
                sqlite.csv line 3: expected 4 columns of data but found 1
$ O0 W+ V2 S( d& c; w1 J. ?                sqlite> ! Z) {$ e$ L/ |8 M( H9 Q) g
我试着使用导入csv表;作为sqlite但是找不到四列分隔符。sql导出到csv,并选择了在第一行放入第一行。我能在这里丢失一些东西吗?. q4 r1 D* G' [/ U0 B4 Q3 w: n; v$ H
CSV的前5行( q$ B1 R/ X4 l; Y; f( t* Q
id;"author_id";"title";"poem"       1;"92";"A Letter From Italy";"Salve magna parens frugum Saturnia tellus     Magna virm! tibi res antiqu laudis et artis     Aggredior    sanctos ausus recludere fontes.    Virg. Geor. 2.               
4 q, Q/ r6 W& _& ^3 D* s  j; P    解决方案:                                                               
* ~. @6 b% H) p9 I% U& A                                                                不能使用主键导入表,必须先导入临时表。: n6 j& x7 z5 m; I! @
看看这个问题的答案
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则