Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I move a Spatialite table from a Spatialite db to a PostgreSQL db using ogr2ogr?

share|improve this question
I know you wanted to use ogr2ogr, and have posted a solution below, but you can also use the VirtualPG support ( if you have a fairly recent SpatiaLite. That can give you a live connection. – BradHards Aug 18 '14 at 7:48
A very cool feature. Works well. – Phil Donovan Aug 18 '14 at 8:09
up vote 8 down vote accepted

And, after a bit more reading the ogr2ogr help I found the answer more easily than I expected.

ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb -sql "SELECT * FROM table" -dialect spatialite -nln new_table

EDIT: As suggested by user30184 in the comments a cleaner, simpler method is:

ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb spatialite_table_name
share|improve this answer
No need to delete it. This kind of thing is fine on GIS.SE. – Nathan W Aug 18 '14 at 4:26
You should mark your answer though as accepted. It's okay to answer your own questions. :) – LR1234567 Aug 18 '14 at 4:30
However, if the whole table with all the attributes should be copied it is more simple with ogr2ogr -f "PostgreSQL" PG:"dbname=db" spatialitedb spatialite_table_name. Select * probably also copies the "rowid" column which you do not need. – user30184 Aug 18 '14 at 4:44
:-o I have to wait 2 days to mark it as the answer. – Phil Donovan Aug 18 '14 at 7:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.