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", "a@i.ua", "..
How to avoid this error?
Thanks in advance!
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
VAULESkeyword, 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.