将文件从 Sqlite3 转储到 PostgreSQL:为什么导入时总是出现错误?
我在 Sqlite3 db 中有很多表,现在我想将其导出到 PostgreSQL,但总是出现错误。 我使用了不同的技术从 sqlite 转储:
.模式csv
.header 上
.out ddd.sql
从 my_table 中选择 *
和
.模式插入
.out ddd.sql
从 my_table 中选择 *
当我尝试通过 phppgadmin 导入它时,我收到如下错误:
错误:关系“my_table”的列“1”不存在
第 1 行:INSERT INTO "public"."my_table" ("1", "1", "Vitas", "[电子邮件受保护]", "..
如何避免这个错误?
提前致谢!
I have many tables in Sqlite3 db and now I want to export it to PostgreSQL, but all the time I get errors.
I've used different techniques to dump from sqlite:
.mode csv
.header on
.out ddd.sql
select * from my_table
and
.mode insert
.out ddd.sql
select * from my_table
And when I try to import it through phppgadmin I get errors like this:
ERROR: column "1" of relation "my_table" does not exist
LINE 1: INSERT INTO "public"."my_table" ("1", "1", "Vitas", "[email protected]", "..
How to avoid this error?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
咆哮
你得到这个“列...不存在”错误
INSERT INTO "public"."my_table" ("1", ...
- 因为引号周围“1”表示这是一个 标识符, 文字。不是 你修复了这个问题,查询仍然会给出错误,因为缺少
VAULES
关键字,正如 Jan 在其他答案中注意到的那样,正确的形式是:
如果此 SQL 是由 sqlite 自动生成的,则对 sqlite 不利
。太棒了关于 SQL 语法的章节打印后只有大约 20 页。无论是谁生成了这个 INSERT,都是:阅读它 :-) 它会得到回报。
真正的解决方案
现在,重点是...要将表从 sqlite 传输到 postgres,您应该使用 COPY,因为它比 INSERT 快得多。
使用双方都能理解的 CSV 格式。
在 sqlite3 中:
在 PostgreSQL(psql 客户端)中:
请参阅 http://wiki.postgresql.org/wiki/COPY< /a>.
Rant
You get this "column ... does not exist" error with
INSERT INTO "public"."my_table" ("1", ...
- because quotes around the "1" mean this is an identifier, not literal.Even if you fix this, the query still will give error, because of missing
VAULES
keyword, as Jan noticed in other answer.The correct form would be:
If this SQL was autogenerated by sqlite, bad for sqlite.
This great chapter about SQL syntax is only about 20 pages in print. My advice to whoever generated this INSERT, is: read it :-) it will pay off.
Real solution
Now, to the point... To transfer table from sqlite to postgres, you should use COPY because it's way faster than INSERT.
Use CSV format as it's understood on both sides.
In sqlite3:
In PostgreSQL (psql client):
See http://wiki.postgresql.org/wiki/COPY.
似乎缺少“VALUES”关键字:
但是! - 您必须插入带有适当引号的值 - 单引号用于文本,不带引号用于数字。
Seems there is missing "VALUES" keyword:
But! - You have to insert values with appropriate quotes - single quotes for text and without quotes for numbers.