gpt4 book ai didi

postgresql - 将文件从 Sqlite3 转储到 PostgreSQL : why do I always get errors when import it?

转载 作者:行者123 更新时间:2023-11-29 12:31:44 25 4
gpt4 key购买 nike

我在 Sqlite3 数据库中有很多表,现在我想将其导出到 PostgreSQL,但总是出现错误。我使用了不同的技术从 sqlite 中转储:

.mode csv

.header on

.out ddd.sql

select * from my_table

.mode insert

.out ddd.sql

select * from my_table

当我尝试通过 phppgadmin 导入它时,出现如下错误:

ERROR: column "1" of relation "my_table" does not exist

LINE 1: INSERT INTO "public"."my_table" ("1", "1", "Vitas", "a@i.ua", "..

如何避免这个错误?

提前致谢!

最佳答案

咆哮

"column ... does not exist" 错误 INSERT INTO "public"."my_table"("1", ... - 因为“1”两边的引号表示这是 identifier,而不是 literal

即使您修复了此问题,查询仍然会出错,因为缺少 VAULES 关键字,正如 Jan 在其他答案中注意到的那样。

正确的形式是:

INSERT INTO "public"."my_table" VALUES ('1', ...

如果此 SQL 是由 sqlite 自动生成的,则对 sqlite 不利。

这很棒 chapter about SQL syntax仅打印了大约 20 页。我对生成此 INSERT 的人的建议是:阅读它 :-) 它会有所收获。

真正的解决方案

现在,重点是...要将表从 sqlite 传输到 postgres,您应该使用 COPY,因为它比 INSERT 快得多。

使用双方都理解的 CSV 格式。

在 sqlite3 中:

create table tbl1(one varchar(20), two smallint);
insert into tbl1 values('hello',10);
insert into tbl1 values('with,comma', 20);
insert into tbl1 values('with "quotes"', 30);
insert into tbl1 values('with
enter', 40);
.mode csv
.header on
.out tbl1.csv
select * from tbl1;

在 PostgreSQL(psql 客户端)中:

create table tbl1(one varchar(20), two smallint);
\copy tbl1 from 'tbl1.csv' with csv header delimiter ','
select * from tbl1;

参见 http://wiki.postgresql.org/wiki/COPY .

关于postgresql - 将文件从 Sqlite3 转储到 PostgreSQL : why do I always get errors when import it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9030990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com