Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
1  
I know you wanted to use ogr2ogr, and have posted a solution below, but you can also use the VirtualPG support (gaia-gis.it/fossil/virtualpg/wiki?name=tutorial) if you have a fairly recent SpatiaLite. That can give you a live connection. –  BradHards Aug 18 at 7:48
    
A very cool feature. Works well. –  Phil Donovan Aug 18 at 8:09

1 Answer 1

up vote 5 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 at 4:26
    
You should mark your answer though as accepted. It's okay to answer your own questions. :) –  LR1234567 Aug 18 at 4:30
3  
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 at 4:44
    
:-o I have to wait 2 days to mark it as the answer. –  Phil Donovan Aug 18 at 7:35

Your Answer

 
discard

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.