Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert SQLite3 script into script that PostgreSQL can understand?

I have a SQLite3 database. I did a data dump which looks something like this:

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
);
......

I'm trying to execute this in PostgreSQL PgAdmin III, which gives me many many errors starting with PRAGMA, to 'unsigned' fields to datetime fields to 1 instead of true and 0 instead of false.

Is there a proper way to convert this script?

I thought of exporting each table to CSV then importing them into a PGDB but I have so many tables this isn't an option.

like image 691
darren Avatar asked Sep 12 '25 04:09

darren


1 Answers

Ruby solution:

gem install sequel

sequel -C sqlite://db/development.sqlite3 postgres://user:password@localhost/dbname
like image 131
Mikhail Chuprynski Avatar answered Sep 13 '25 18:09

Mikhail Chuprynski