Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将SQLite3脚本转换为PostgreSQL能够理解的脚本?_Sql_Postgresql_Sqlite - Fatal编程技术网

如何将SQLite3脚本转换为PostgreSQL能够理解的脚本?

如何将SQLite3脚本转换为PostgreSQL能够理解的脚本?,sql,postgresql,sqlite,Sql,Postgresql,Sqlite,我有一个SQLite3数据库。我做了一个数据转储,看起来像这样: PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE "admin_tools_menu_bookmark" ( "id" integer NOT NULL PRIMARY KEY, "user_id" integer NOT NULL, "url" varchar(255) NOT NULL, "title" varchar(255) N

我有一个SQLite3数据库。我做了一个数据转储,看起来像这样:

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE "admin_tools_menu_bookmark" (
    "id" integer NOT NULL PRIMARY KEY,
    "user_id" integer NOT NULL,
    "url" varchar(255) NOT NULL,
    "title" varchar(255) NOT NULL
);
INSERT INTO "admin_tools_menu_bookmark" VALUES(1,2,'/admin/recipes/recipe/','Recipe Management');
INSERT INTO "admin_tools_menu_bookmark" VALUES(2,2,'/admin/recipes/ingredient/','Ingredient Management');
CREATE TABLE "admin_tools_dashboard_preferences" (
    "id" integer NOT NULL PRIMARY KEY,
    "user_id" integer NOT NULL,
    "data" text NOT NULL
);
......
我试图在PostgreSQL PgAdmin III中执行此操作,这会给我带来许多错误,从
PRAGMA开始,到“unsigned”字段到datetime字段,从1到true,从0到false

是否有正确的方法转换此脚本


我曾想过将每个表导出到CSV,然后将它们导入PGDB,但我有太多的表,这不是一个选项。

使用一个可以在数据库之间复制数据的工具,如

有一个问题

注意,这仍然需要大量的手工工作。JDBC驱动程序将允许复制数据,但仍然需要手动转换表定义


或者你可以写一个工具,做简单的字符串替换;这通常对SQL非常有效。

我想
PRAGMA foregin\u keys…
是一些在PostgreSQL中不起作用的SQLite语法。
你能简单地跳过它并做:

BEGIN TRANSACTION;
CREATE TABLE "admin_tools_menu_bookmark" (
    "id" integer NOT NULL PRIMARY KEY,
    "user_id" integer NOT NULL,
    "url" varchar(255) NOT NULL,
    "title" varchar(255) NOT NULL
);
INSERT INTO "admin_tools_menu_bookmark" VALUES(1,2,'/admin/recipes/recipe/','Recipe Management');
INSERT INTO "admin_tools_menu_bookmark" VALUES(2,2,'/admin/recipes/ingredient/','Ingredient Management');
CREATE TABLE "admin_tools_dashboard_preferences" (
    "id" integer NOT NULL PRIMARY KEY,
    "user_id" integer NOT NULL,
    "data" text NOT NULL
);
COMMIT;  

我在我的pgAdmin III中对它进行了测试,结果正常。

我使用了一个名为Navicat的程序。我导出了每个表,然后将它们导入到新的数据库中,这既痛苦又缓慢

当我将SQL放入PG Admin III时,使用SQLiteman的SQL转储不是个好兆头。

Ruby解决方案:

gem install sequel

sequel -C sqlite://db/development.sqlite3 postgres://user:password@localhost/dbname

我的sql有超过15000行,有许多部分不起作用,比如unsigned、datetime等等。现在正在试用squirrel。我甚至不知道从哪里开始使用JDBC。您使用了什么来创建这个转储?根据-section#将整个数据库转换为ASCII文本文件#-“.dump”命令创建的输出应与其他数据库兼容(也称为标准SQL)。可能与